Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import pipeline, AutoTokenizer, AutoModelForCausalLM
|
| 2 |
+
import gradio as gr
|
| 3 |
+
|
| 4 |
+
# Load your model (replace with your model ID)
|
| 5 |
+
model_id = "yourusername/your-model-name"
|
| 6 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 7 |
+
model = AutoModelForCausalLM.from_pretrained(model_id)
|
| 8 |
+
chatbot = pipeline("conversational", model=model, tokenizer=tokenizer)
|
| 9 |
+
|
| 10 |
+
# Chat function with memory
|
| 11 |
+
def respond(message, history):
|
| 12 |
+
conversation = []
|
| 13 |
+
for user_msg, bot_msg in history:
|
| 14 |
+
conversation.append({"role": "user", "content": user_msg})
|
| 15 |
+
conversation.append({"role": "assistant", "content": bot_msg})
|
| 16 |
+
conversation.append({"role": "user", "content": message})
|
| 17 |
+
|
| 18 |
+
response = chatbot(conversation)
|
| 19 |
+
return response[-1]["generated_text"]
|
| 20 |
+
|
| 21 |
+
# Launch interface
|
| 22 |
+
gr.ChatInterface(respond).launch()
|