File size: 740 Bytes
ff6ecba
471c3dc
 
 
 
14cf96e
471c3dc
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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()