Tipsy_hosting / app.py
Badbunny123's picture
Update app.py
14cf96e verified
raw
history blame contribute delete
740 Bytes
import gradio as gr
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
# Load the Pygmalion Model
model_name = "PygmalionAI/Pygmalion-2-7B" # You can change to Pygmalion-3B if needed
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.float16, device_map="auto")
# Chat Function
def chat_with_ai(prompt):
inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
outputs = model.generate(**inputs, max_length=200)
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
return response
# Gradio UI
iface = gr.Interface(fn=chat_with_ai, inputs="text", outputs="text", title="Pygmalion Chatbot")
iface.launch()