Spaces:
Build error
Build error
updating respond function
Browse files
app.py
CHANGED
|
@@ -57,15 +57,21 @@ def respond(message, history, system_message, max_tokens, temperature, top_p):
|
|
| 57 |
prompt = f"{system_message}\nUser: {message}\nAnswer:"
|
| 58 |
response = ""
|
| 59 |
|
| 60 |
-
for chunk in client.
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
):
|
| 67 |
-
|
| 68 |
-
|
|
|
|
|
|
|
| 69 |
|
| 70 |
if not response.strip():
|
| 71 |
yield "⚠️ No response from model (check model ID or token)."
|
|
@@ -75,6 +81,7 @@ def respond(message, history, system_message, max_tokens, temperature, top_p):
|
|
| 75 |
yield f"⚠️ Error: {str(e)}\n\nTraceback:\n{tb}"
|
| 76 |
|
| 77 |
|
|
|
|
| 78 |
chatbot = gr.ChatInterface(
|
| 79 |
fn=respond,
|
| 80 |
additional_inputs=[
|
|
|
|
| 57 |
prompt = f"{system_message}\nUser: {message}\nAnswer:"
|
| 58 |
response = ""
|
| 59 |
|
| 60 |
+
for chunk in client.post(
|
| 61 |
+
json={
|
| 62 |
+
"inputs": prompt,
|
| 63 |
+
"parameters": {
|
| 64 |
+
"max_new_tokens": max_tokens,
|
| 65 |
+
"temperature": temperature,
|
| 66 |
+
"top_p": top_p,
|
| 67 |
+
},
|
| 68 |
+
"stream": True,
|
| 69 |
+
}
|
| 70 |
):
|
| 71 |
+
if "token" in chunk:
|
| 72 |
+
token = chunk["token"]["text"]
|
| 73 |
+
response += token
|
| 74 |
+
yield response.strip()
|
| 75 |
|
| 76 |
if not response.strip():
|
| 77 |
yield "⚠️ No response from model (check model ID or token)."
|
|
|
|
| 81 |
yield f"⚠️ Error: {str(e)}\n\nTraceback:\n{tb}"
|
| 82 |
|
| 83 |
|
| 84 |
+
|
| 85 |
chatbot = gr.ChatInterface(
|
| 86 |
fn=respond,
|
| 87 |
additional_inputs=[
|