Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -11,7 +11,6 @@ MODEL = "nomiChroma3.1"
|
|
11 |
|
12 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
13 |
|
14 |
-
|
15 |
def respond(
|
16 |
message,
|
17 |
history: list[tuple[str, str]],
|
@@ -21,28 +20,41 @@ def respond(
|
|
21 |
top_p,
|
22 |
):
|
23 |
messages = [{"role": "system", "content": system_message}]
|
24 |
-
|
25 |
for val in history:
|
26 |
if val[0]:
|
27 |
messages.append({"role": "user", "content": val[0]})
|
28 |
if val[1]:
|
29 |
messages.append({"role": "assistant", "content": val[1]})
|
30 |
-
|
31 |
messages.append({"role": "user", "content": message})
|
32 |
-
|
33 |
response = ""
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
|
47 |
"""
|
48 |
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
|
|
11 |
|
12 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
13 |
|
|
|
14 |
def respond(
|
15 |
message,
|
16 |
history: list[tuple[str, str]],
|
|
|
20 |
top_p,
|
21 |
):
|
22 |
messages = [{"role": "system", "content": system_message}]
|
|
|
23 |
for val in history:
|
24 |
if val[0]:
|
25 |
messages.append({"role": "user", "content": val[0]})
|
26 |
if val[1]:
|
27 |
messages.append({"role": "assistant", "content": val[1]})
|
|
|
28 |
messages.append({"role": "user", "content": message})
|
|
|
29 |
response = ""
|
30 |
+
try:
|
31 |
+
for message in client.chat_completion(
|
32 |
+
messages,
|
33 |
+
max_tokens=max_tokens,
|
34 |
+
stream=True,
|
35 |
+
temperature=temperature,
|
36 |
+
top_p=top_p,
|
37 |
+
):
|
38 |
+
try:
|
39 |
+
# Try to access the content directly
|
40 |
+
token = message.choices[0].delta.content
|
41 |
+
except AttributeError:
|
42 |
+
# If above fails, the response might be in a different format
|
43 |
+
# Print the raw message for debugging
|
44 |
+
print(f"Debug - Raw message: {message}")
|
45 |
+
# Try to parse as JSON
|
46 |
+
try:
|
47 |
+
parsed_message = json.loads(str(message))
|
48 |
+
token = parsed_message.get('choices', [{}])[0].get('delta', {}).get('content', '')
|
49 |
+
except json.JSONDecodeError as e:
|
50 |
+
print(f"JSON Decode Error: {e}")
|
51 |
+
print(f"Problematic message: {message}")
|
52 |
+
token = "" # or handle this case as appropriate
|
53 |
+
response += token
|
54 |
+
yield response
|
55 |
+
except Exception as e:
|
56 |
+
print(f"An error occurred: {e}")
|
57 |
+
yield f"An error occurred: {e}"
|
58 |
|
59 |
"""
|
60 |
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|