Spaces:
Runtime error
Runtime error
Threatthriver
commited on
Commit
•
3e4a10f
1
Parent(s):
0151088
Update app.py
Browse files
app.py
CHANGED
@@ -46,40 +46,23 @@ def respond(
|
|
46 |
except Exception as e:
|
47 |
yield f"**Error:** {str(e)}"
|
48 |
|
49 |
-
# Latest updates (this is just placeholder text)
|
50 |
-
latest_updates = """
|
51 |
-
**Chatbot - Latest Updates:**
|
52 |
|
53 |
-
|
54 |
-
* Improved Error Handling
|
55 |
-
* Enhanced System Message Input
|
56 |
-
"""
|
57 |
-
|
58 |
-
def show_updates_and_respond(history, system_message, max_tokens, temperature, top_p, model_name):
|
59 |
"""
|
60 |
-
|
61 |
"""
|
62 |
-
history.append(("User",
|
63 |
-
|
64 |
-
message=
|
65 |
-
history=history,
|
66 |
-
system_message=system_message,
|
67 |
-
max_tokens=max_tokens,
|
68 |
-
temperature=temperature,
|
69 |
-
top_p=top_p,
|
70 |
-
model_name=model_name,
|
71 |
-
)
|
72 |
-
history[-1] = ("User", "Show me the latest updates")
|
73 |
-
history.append(("Assistant", latest_updates))
|
74 |
-
yield from respond(
|
75 |
-
message="What are the latest updates?",
|
76 |
history=history,
|
77 |
system_message=system_message,
|
78 |
max_tokens=max_tokens,
|
79 |
temperature=temperature,
|
80 |
top_p=top_p,
|
81 |
-
model_name=model_name
|
82 |
-
)
|
|
|
|
|
83 |
|
84 |
# Define the Gradio interface with the Blocks context
|
85 |
with gr.Blocks(css=".gradio-container {border: none;}") as demo:
|
@@ -94,17 +77,17 @@ with gr.Blocks(css=".gradio-container {border: none;}") as demo:
|
|
94 |
top_p = gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)")
|
95 |
model_dropdown = gr.Dropdown(choices=list(available_models.keys()), value="Zephyr 7B Beta", label="Select Model")
|
96 |
|
97 |
-
|
98 |
-
chatbot = gr.Chatbot()
|
99 |
|
100 |
-
|
101 |
-
|
102 |
|
103 |
-
#
|
104 |
-
|
105 |
-
fn=
|
106 |
-
inputs=[chat_history, system_message, max_tokens, temperature, top_p
|
107 |
-
outputs=
|
|
|
108 |
)
|
109 |
|
110 |
# Launch the Gradio interface
|
|
|
46 |
except Exception as e:
|
47 |
yield f"**Error:** {str(e)}"
|
48 |
|
|
|
|
|
|
|
49 |
|
50 |
+
def update_chatbox(history, message, model_name, system_message, max_tokens, temperature, top_p):
|
|
|
|
|
|
|
|
|
|
|
51 |
"""
|
52 |
+
Update the chat history and generate the next AI response.
|
53 |
"""
|
54 |
+
history.append(("User", message)) # Add user message to history
|
55 |
+
ai_response = next(respond(
|
56 |
+
message=message,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
history=history,
|
58 |
system_message=system_message,
|
59 |
max_tokens=max_tokens,
|
60 |
temperature=temperature,
|
61 |
top_p=top_p,
|
62 |
+
model_name=model_name
|
63 |
+
))
|
64 |
+
history.append(("AI", ai_response)) # Add AI response to history
|
65 |
+
return history, "" # Return updated history and clear the user input
|
66 |
|
67 |
# Define the Gradio interface with the Blocks context
|
68 |
with gr.Blocks(css=".gradio-container {border: none;}") as demo:
|
|
|
77 |
top_p = gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)")
|
78 |
model_dropdown = gr.Dropdown(choices=list(available_models.keys()), value="Zephyr 7B Beta", label="Select Model")
|
79 |
|
80 |
+
chatbot = gr.Chatbot(label="Character-like AI Chat")
|
|
|
81 |
|
82 |
+
user_input = gr.Textbox(show_label=False, placeholder="Type your message here...")
|
83 |
+
send_button = gr.Button("Send")
|
84 |
|
85 |
+
# When the send button is clicked, update chat history
|
86 |
+
send_button.click(
|
87 |
+
fn=update_chatbox,
|
88 |
+
inputs=[chat_history, user_input, model_dropdown, system_message, max_tokens, temperature, top_p],
|
89 |
+
outputs=[chatbot, user_input], # Update chatbox and clear user input
|
90 |
+
queue=True # Ensure responses are shown in order
|
91 |
)
|
92 |
|
93 |
# Launch the Gradio interface
|