Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,28 +1,38 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
|
| 28 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 3 |
+
import torch
|
| 4 |
+
|
| 5 |
+
# Load the model and tokenizer
|
| 6 |
+
model_name = "Qwen/Qwen2.5-72B-Instruct"
|
| 7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 8 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
| 9 |
+
|
| 10 |
+
# Define the chat function
|
| 11 |
+
def chatbot(input_text):
|
| 12 |
+
inputs = tokenizer.encode(input_text, return_tensors="pt")
|
| 13 |
+
outputs = model.generate(inputs, max_length=150, num_return_sequences=1)
|
| 14 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 15 |
+
return response
|
| 16 |
+
|
| 17 |
+
# Define the Gradio interface
|
| 18 |
+
css = """
|
| 19 |
+
.gradio-container {
|
| 20 |
+
background-color: #8C9A61; /* Sage Green */
|
| 21 |
+
font-family: 'Times New Roman', Times, serif;
|
| 22 |
+
}
|
| 23 |
+
"""
|
| 24 |
+
|
| 25 |
+
iface = gr.Interface(
|
| 26 |
+
fn=chatbot,
|
| 27 |
+
inputs=gr.Textbox(label="You:"),
|
| 28 |
+
outputs=gr.Textbox(label="Chatbot:"),
|
| 29 |
+
title="Qwen Chatbot",
|
| 30 |
+
description="A chatbot using the Qwen/Qwen2.5-72B-Instruct model.",
|
| 31 |
+
css=css
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
# Launch the interface
|
| 35 |
+
iface.launch()
|
| 36 |
|
| 37 |
|
| 38 |
|