kdevoe commited on
Commit
616f6e6
·
verified ·
1 Parent(s): 923a0bd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -14
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
- return response
 
 
 
63
 
64
- # Set up the Gradio interface with additional sliders
65
- interface = gr.Interface(
66
- fn=chat_with_distilgpt2,
67
- inputs=[
68
- gr.Textbox(label="Chat with DistilGPT-2"), # User input text
69
- gr.Slider(0.1, 1.0, step=0.1, value=1.0, label="Temperature"), # Slider for temperature
70
- gr.Slider(0.0, 1.0, step=0.1, value=1.0, label="Top-p"), # Slider for top-p
71
- gr.Slider(1, 100, step=1, value=50, label="Top-k") # Slider for top-k
72
- ],
73
- outputs=gr.Textbox(label="DistilGPT-2's Response"), # Model response
74
- title="DistilGPT-2 Chatbot with Memory and Adjustable Parameters",
75
- description="This is a simple chatbot powered by the DistilGPT-2 model with conversational memory, using LangChain. You can adjust temperature, top-p, and top-k using the sliders.",
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
+