Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -100,35 +100,20 @@ def generate_response(messages):
|
|
100 |
|
101 |
return result[0]["generated_text"]
|
102 |
|
103 |
-
def chat_interface(
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
messages.append({"role": "assistant", "content": msg[1]})
|
113 |
-
|
114 |
-
messages.append({"role": "user", "content": message})
|
115 |
-
|
116 |
-
response = generate_response(messages)
|
117 |
-
|
118 |
-
chat_history.append((message, response))
|
119 |
-
return chat_history
|
120 |
-
except Exception as e:
|
121 |
-
chat_history.append((message, f"Error: {str(e)}"))
|
122 |
-
return chat_history
|
123 |
|
124 |
# Create Gradio interface
|
125 |
demo = gr.Chatbot(
|
126 |
chat_interface,
|
127 |
-
|
128 |
-
examples=[
|
129 |
-
"Hello! Can you help me with coding?",
|
130 |
-
"Write a simple Python function to calculate factorial"
|
131 |
-
]
|
132 |
)
|
133 |
|
134 |
# Mount both FastAPI and Gradio
|
|
|
100 |
|
101 |
return result[0]["generated_text"]
|
102 |
|
103 |
+
def chat_interface(messages):
|
104 |
+
chat_history = []
|
105 |
+
for message in messages:
|
106 |
+
try:
|
107 |
+
response = generate_response([{"role": "user", "content": message}])
|
108 |
+
chat_history.append((message, response))
|
109 |
+
except Exception as e:
|
110 |
+
chat_history.append((message, f"Error: {str(e)}"))
|
111 |
+
return chat_history
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
112 |
|
113 |
# Create Gradio interface
|
114 |
demo = gr.Chatbot(
|
115 |
chat_interface,
|
116 |
+
type="messages"
|
|
|
|
|
|
|
|
|
117 |
)
|
118 |
|
119 |
# Mount both FastAPI and Gradio
|