Update app.py
Browse files
app.py
CHANGED
|
@@ -2,12 +2,12 @@ import gradio as gr
|
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
# Function to generate text based on the model
|
| 5 |
-
def chatbot(user_input, history
|
| 6 |
# Load the selected model (using a hard-coded model for now)
|
| 7 |
model = pipeline("text-generation", model="google/mt5-base")
|
| 8 |
|
| 9 |
# Get the model's response
|
| 10 |
-
response = model(user_input, max_length=
|
| 11 |
|
| 12 |
# Append the user input and model's response to the history
|
| 13 |
history.append({"role": "user", "content": user_input})
|
|
@@ -33,16 +33,10 @@ def create_chat_interface():
|
|
| 33 |
with gr.Column(scale=0.1):
|
| 34 |
send_button = gr.Button("📤", elem_id="send_button", scale=1)
|
| 35 |
|
| 36 |
-
# Define settings menu, initially hidden
|
| 37 |
-
with gr.Accordion("Settings", open=False) as settings:
|
| 38 |
-
with gr.Column():
|
| 39 |
-
max_length = gr.Slider(minimum=10, maximum=200, value=50, label="Max Length")
|
| 40 |
-
temperature = gr.Slider(minimum=0.1, maximum=2.0, step=0.1, value=1.0, label="Temperature")
|
| 41 |
-
|
| 42 |
# Connect the input to the chatbot function via the Send button
|
| 43 |
send_button.click(
|
| 44 |
chatbot,
|
| 45 |
-
inputs=[user_input, chatbot_component
|
| 46 |
outputs=chatbot_component,
|
| 47 |
)
|
| 48 |
|
|
|
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
# Function to generate text based on the model
|
| 5 |
+
def chatbot(user_input, history):
|
| 6 |
# Load the selected model (using a hard-coded model for now)
|
| 7 |
model = pipeline("text-generation", model="google/mt5-base")
|
| 8 |
|
| 9 |
# Get the model's response
|
| 10 |
+
response = model(user_input, max_length=50, temperature=1.0)[0]["generated_text"]
|
| 11 |
|
| 12 |
# Append the user input and model's response to the history
|
| 13 |
history.append({"role": "user", "content": user_input})
|
|
|
|
| 33 |
with gr.Column(scale=0.1):
|
| 34 |
send_button = gr.Button("📤", elem_id="send_button", scale=1)
|
| 35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
# Connect the input to the chatbot function via the Send button
|
| 37 |
send_button.click(
|
| 38 |
chatbot,
|
| 39 |
+
inputs=[user_input, chatbot_component],
|
| 40 |
outputs=chatbot_component,
|
| 41 |
)
|
| 42 |
|