Spaces:
Runtime error
Runtime error
SpaceGhost
commited on
Commit
•
48d5610
1
Parent(s):
c00c0fb
Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import InferenceClient
|
3 |
|
@@ -5,9 +6,7 @@ from huggingface_hub import InferenceClient
|
|
5 |
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
6 |
"""
|
7 |
#client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
8 |
-
|
9 |
-
#client = InferenceClient("microsoft/Phi-3.5-mini-instruct")
|
10 |
-
client = InferenceClient("SpaceGhost-2-3B.Q4_K_M.gguf")
|
11 |
|
12 |
|
13 |
def respond(
|
@@ -31,15 +30,47 @@ def respond(
|
|
31 |
response = ""
|
32 |
|
33 |
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
|
42 |
-
|
|
|
|
|
43 |
|
44 |
|
45 |
"""
|
@@ -48,7 +79,7 @@ For information on how to customize the ChatInterface, peruse the gradio docs: h
|
|
48 |
demo = gr.ChatInterface(
|
49 |
respond,
|
50 |
additional_inputs=[
|
51 |
-
gr.Textbox(value="Você é uma IA de nome SpaceGhost com uma vibe de pessoa sempre alto-astral, cheia de energia positiva e pronta para dar aquele apoio", label="System message"),
|
52 |
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
53 |
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
54 |
gr.Slider(
|
|
|
1 |
+
|
2 |
import gradio as gr
|
3 |
from huggingface_hub import InferenceClient
|
4 |
|
|
|
6 |
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
7 |
"""
|
8 |
#client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
9 |
+
client = InferenceClient("SpaceGhost/SpaceGhost-2-3B-GGUF")
|
|
|
|
|
10 |
|
11 |
|
12 |
def respond(
|
|
|
30 |
response = ""
|
31 |
|
32 |
|
33 |
+
try:
|
34 |
+
for message in client.chat_completion(
|
35 |
+
messages,
|
36 |
+
max_tokens=max_tokens,
|
37 |
+
stream=True,
|
38 |
+
temperature=temperature,
|
39 |
+
top_p=top_p,
|
40 |
+
):
|
41 |
+
# Ensure the message has a valid structure
|
42 |
+
if not message or not isinstance(message, dict):
|
43 |
+
continue
|
44 |
+
|
45 |
+
try:
|
46 |
+
# Extract content and finish reason
|
47 |
+
content = message.choices[0].delta.content
|
48 |
+
finish_reason = message.choices[0].finish_reason
|
49 |
+
|
50 |
+
# Check if the content is empty
|
51 |
+
if content.strip() == "":
|
52 |
+
# If the finish reason is 'stop', it's expected and we can break the loop
|
53 |
+
if finish_reason == "stop":
|
54 |
+
print("Stream ended normally.")
|
55 |
+
break
|
56 |
+
else:
|
57 |
+
print("Received unexpected empty content, skipping...")
|
58 |
+
continue
|
59 |
+
|
60 |
+
response += content
|
61 |
+
yield response
|
62 |
+
|
63 |
+
except (AttributeError, IndexError, KeyError) as e:
|
64 |
+
print(f"Error processing message: {e}")
|
65 |
+
continue
|
66 |
+
|
67 |
+
except Exception as e:
|
68 |
+
print(f"Unexpected error: {e}")
|
69 |
+
yield "An error occurred while generating the response."
|
70 |
|
71 |
+
# Final check if the response is empty
|
72 |
+
if response.strip() == "":
|
73 |
+
yield "No response generated. Please try again or adjust the settings."
|
74 |
|
75 |
|
76 |
"""
|
|
|
79 |
demo = gr.ChatInterface(
|
80 |
respond,
|
81 |
additional_inputs=[
|
82 |
+
gr.Textbox(value="Você é uma IA de nome SpaceGhost com uma vibe de pessoa sempre alto-astral, cheia de energia positiva e pronta para dar aquele apoio! 😄", label="System message"),
|
83 |
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
84 |
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
85 |
gr.Slider(
|