Threatthriver commited on
Commit
1c9a4c1
1 Parent(s): c51870d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -32
app.py CHANGED
@@ -73,46 +73,47 @@ def show_updates_and_respond(history, system_message, max_tokens, temperature, t
73
  model_name=model_name,
74
  )
75
 
76
- # Define the Gradio interface with the Blocks context
77
  with gr.Blocks(css=".gradio-container {border: none;}") as demo:
78
  chat_history = gr.State([]) # Initialize an empty chat history state
79
- chat_interface = gr.ChatInterface(
80
- fn=respond,
81
- additional_inputs=[
82
- gr.Textbox(
83
- value="You are a friendly and helpful assistant.",
84
- label="System message",
85
- lines=2
86
- ),
87
- gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
88
- gr.Slider(minimum=0.1, maximum=2.0, value=0.7, step=0.1, label="Temperature"),
89
- gr.Slider(
90
- minimum=0.1,
91
- maximum=1.0,
92
- value=0.95,
93
- step=0.05,
94
- label="Top-p (nucleus sampling)",
95
- ),
96
- gr.Dropdown(
97
- choices=list(available_models.keys()),
98
- value="Zephyr 7B Beta",
99
- label="Select Model",
100
- ),
101
- ],
102
- title="Multi-Model Chatbot",
103
- description="A customizable chatbot interface using Hugging Face's Inference API.",
104
- chat_history=chat_history, # Pass the state to the ChatInterface
 
 
 
105
  )
106
 
107
  # Add the "Show Updates" button and output area
108
- with gr.Row():
109
- updates_button = gr.Button("Show Latest Updates")
110
 
111
- # Define the button's click event (now inside the Blocks context)
112
  updates_button.click(
113
  fn=show_updates_and_respond,
114
- inputs=[chat_history, chat_interface.textbox, gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"), gr.Slider(minimum=0.1, maximum=2.0, value=0.7, step=0.1, label="Temperature"), gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)"), chat_interface.dropdown],
115
- outputs=chat_history
116
  )
117
 
118
  # Launch the Gradio interface in full screen
 
73
  model_name=model_name,
74
  )
75
 
76
+ # Define the Gradio interface
77
  with gr.Blocks(css=".gradio-container {border: none;}") as demo:
78
  chat_history = gr.State([]) # Initialize an empty chat history state
79
+ system_message = gr.Textbox(
80
+ value="You are a friendly and helpful assistant.",
81
+ label="System message",
82
+ lines=2
83
+ )
84
+ max_tokens_slider = gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens")
85
+ temperature_slider = gr.Slider(minimum=0.1, maximum=2.0, value=0.7, step=0.1, label="Temperature")
86
+ top_p_slider = gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)")
87
+ model_dropdown = gr.Dropdown(
88
+ choices=list(available_models.keys()),
89
+ value="Zephyr 7B Beta",
90
+ label="Select Model",
91
+ )
92
+
93
+ chatbot = gr.Chatbot()
94
+
95
+ def user_interaction(message, history, system_message, max_tokens, temperature, top_p, model_name):
96
+ history = history or []
97
+ history.append(("User", message))
98
+ bot_response = next(respond(message, history, system_message, max_tokens, temperature, top_p, model_name))
99
+ history.append(("Assistant", bot_response))
100
+ return history, history
101
+
102
+ message_input = gr.Textbox(label="Your message")
103
+
104
+ message_input.submit(
105
+ fn=user_interaction,
106
+ inputs=[message_input, chat_history, system_message, max_tokens_slider, temperature_slider, top_p_slider, model_dropdown],
107
+ outputs=[chatbot, chat_history],
108
  )
109
 
110
  # Add the "Show Updates" button and output area
111
+ updates_button = gr.Button("Show Latest Updates")
 
112
 
 
113
  updates_button.click(
114
  fn=show_updates_and_respond,
115
+ inputs=[chat_history, system_message, max_tokens_slider, temperature_slider, top_p_slider, model_dropdown],
116
+ outputs=[chatbot],
117
  )
118
 
119
  # Launch the Gradio interface in full screen