Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -59,22 +59,41 @@ def chat_with_distilgpt2(input_text, temperature, top_p, top_k):
|
|
| 59 |
# Update the memory with the user input and model response
|
| 60 |
memory.save_context({"input": input_text}, {"output": response})
|
| 61 |
|
| 62 |
-
|
|
|
|
|
|
|
|
|
|
| 63 |
|
| 64 |
-
# Set up the Gradio interface with
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
|
|
|
|
|
|
|
|
|
|
| 78 |
# Launch the Gradio app
|
| 79 |
interface.launch()
|
| 80 |
|
|
|
|
|
|
|
|
|
| 59 |
# Update the memory with the user input and model response
|
| 60 |
memory.save_context({"input": input_text}, {"output": response})
|
| 61 |
|
| 62 |
+
# Format the chat history for display
|
| 63 |
+
chat_history = conversation_history + f"\nYou: {input_text}\nBot: {response}\n"
|
| 64 |
+
|
| 65 |
+
return chat_history
|
| 66 |
|
| 67 |
+
# Set up the Gradio interface with the input box below the output box
|
| 68 |
+
with gr.Blocks() as interface:
|
| 69 |
+
chatbot_output = gr.Textbox(label="Conversation", lines=15, placeholder="Chat history will appear here...", interactive=False)
|
| 70 |
+
|
| 71 |
+
# Add the instruction message above the input box
|
| 72 |
+
gr.Markdown("**Instructions:** Press `Shift + Enter` to submit, and `Enter` for a new line.")
|
| 73 |
+
|
| 74 |
+
# Input box for the user
|
| 75 |
+
user_input = gr.Textbox(label="Your Input", placeholder="Type your message here...", lines=2, show_label=True)
|
| 76 |
+
|
| 77 |
+
# Sliders for temperature, top_p, and top_k
|
| 78 |
+
temperature_slider = gr.Slider(0.1, 1.0, step=0.1, value=1.0, label="Temperature")
|
| 79 |
+
top_p_slider = gr.Slider(0.0, 1.0, step=0.1, value=1.0, label="Top-p")
|
| 80 |
+
top_k_slider = gr.Slider(1, 100, step=1, value=50, label="Top-k")
|
| 81 |
+
|
| 82 |
+
# Define the function to update the chat
|
| 83 |
+
def update_chat(input_text, chat_history, temperature, top_p, top_k):
|
| 84 |
+
updated_history = chat_with_distilgpt2(input_text, temperature, top_p, top_k)
|
| 85 |
+
return updated_history, ""
|
| 86 |
+
|
| 87 |
+
# Submit when pressing Shift + Enter
|
| 88 |
+
user_input.submit(update_chat,
|
| 89 |
+
inputs=[user_input, chatbot_output, temperature_slider, top_p_slider, top_k_slider],
|
| 90 |
+
outputs=[chatbot_output, user_input])
|
| 91 |
|
| 92 |
+
# Layout for sliders and chatbot UI
|
| 93 |
+
gr.Row([temperature_slider, top_p_slider, top_k_slider])
|
| 94 |
+
|
| 95 |
# Launch the Gradio app
|
| 96 |
interface.launch()
|
| 97 |
|
| 98 |
+
|
| 99 |
+
|