Spaces:
Runtime error
Runtime error
michailroussos
commited on
Commit
·
be78dc3
1
Parent(s):
6300d69
more
Browse files
app.py
CHANGED
@@ -26,10 +26,8 @@ def respond(message, history, system_message, max_tokens, temperature, top_p):
|
|
26 |
if history:
|
27 |
print("Adding previous messages to the history...")
|
28 |
for entry in history:
|
29 |
-
|
30 |
-
|
31 |
-
messages.append({"role": "user", "content": entry["user"]})
|
32 |
-
messages.append({"role": "assistant", "content": entry["assistant"]})
|
33 |
|
34 |
# Add the current user message
|
35 |
print(f"Adding current user message: {message}")
|
@@ -71,33 +69,19 @@ def respond(message, history, system_message, max_tokens, temperature, top_p):
|
|
71 |
response = tokenizer.decode(generated_tokens[0], skip_special_tokens=True)
|
72 |
print(f"Generated response: {response}")
|
73 |
|
74 |
-
# Update the conversation history with the new user-assistant pair
|
75 |
-
if history is None:
|
76 |
-
history = []
|
77 |
-
history.append({"user": message, "assistant": response})
|
78 |
-
|
79 |
# Check and filter out unwanted system-level messages or metadata
|
80 |
if "system" in response.lower():
|
81 |
print("System message detected. Replacing with fallback response.")
|
82 |
-
response = "
|
83 |
|
84 |
-
# Prepare the
|
85 |
-
|
86 |
-
|
87 |
-
for entry in history:
|
88 |
-
print(f"Formatting user message for history: {entry['user']}")
|
89 |
-
print(f"Formatting assistant message for history: {entry['assistant']}")
|
90 |
-
formatted_history.append({"role": "user", "content": entry["user"]})
|
91 |
-
formatted_history.append({"role": "assistant", "content": entry["assistant"]})
|
92 |
-
|
93 |
-
# Print the final formatted history before returning
|
94 |
-
print(f"Formatted history for Gradio: {formatted_history}")
|
95 |
|
96 |
-
#
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
|
|
|
101 |
|
102 |
# Define the Gradio interface
|
103 |
demo = gr.ChatInterface(
|
@@ -108,9 +92,7 @@ demo = gr.ChatInterface(
|
|
108 |
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
109 |
gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p"),
|
110 |
],
|
111 |
-
type="messages",
|
112 |
)
|
113 |
|
114 |
-
|
115 |
if __name__ == "__main__":
|
116 |
-
demo.launch(share=False) # Use share=False for local testing
|
|
|
26 |
if history:
|
27 |
print("Adding previous messages to the history...")
|
28 |
for entry in history:
|
29 |
+
messages.append({"role": "user", "content": entry[0]})
|
30 |
+
messages.append({"role": "assistant", "content": entry[1]})
|
|
|
|
|
31 |
|
32 |
# Add the current user message
|
33 |
print(f"Adding current user message: {message}")
|
|
|
69 |
response = tokenizer.decode(generated_tokens[0], skip_special_tokens=True)
|
70 |
print(f"Generated response: {response}")
|
71 |
|
|
|
|
|
|
|
|
|
|
|
72 |
# Check and filter out unwanted system-level messages or metadata
|
73 |
if "system" in response.lower():
|
74 |
print("System message detected. Replacing with fallback response.")
|
75 |
+
response = "Hello! How can I assist you today?"
|
76 |
|
77 |
+
# Prepare the return format for Gradio (list of [user_message, assistant_message])
|
78 |
+
if history is None:
|
79 |
+
history = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
|
81 |
+
# Append the new conversation turn
|
82 |
+
history.append([message, response])
|
|
|
|
|
83 |
|
84 |
+
return history
|
85 |
|
86 |
# Define the Gradio interface
|
87 |
demo = gr.ChatInterface(
|
|
|
92 |
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
93 |
gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p"),
|
94 |
],
|
|
|
95 |
)
|
96 |
|
|
|
97 |
if __name__ == "__main__":
|
98 |
+
demo.launch(share=False) # Use share=False for local testing
|