Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,21 +1,50 @@
|
|
1 |
-
from gradio_client import Client
|
2 |
|
3 |
-
|
|
|
4 |
|
5 |
-
|
6 |
-
|
7 |
-
|
|
|
8 |
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
max_tokens=100,
|
|
|
14 |
temperature=0.7,
|
15 |
top_p=0.60,
|
16 |
-
api_name="/chat"
|
17 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
-
# Print response with a blank line for better readability
|
20 |
-
print("\nAI:\n")
|
21 |
-
print(result)
|
|
|
|
|
1 |
|
2 |
+
import gradio as gr
|
3 |
+
from huggingface_hub import InferenceClient
|
4 |
|
5 |
+
"""
|
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 |
|
10 |
+
|
11 |
+
def respond(
|
12 |
+
message,
|
13 |
+
history: list[tuple[str, str]],
|
14 |
+
system_message,
|
15 |
+
max_tokens,
|
16 |
+
temperature,
|
17 |
+
top_p,
|
18 |
+
):
|
19 |
+
messages = [{"role": "system", "content": system_message}]
|
20 |
+
|
21 |
+
for val in history:
|
22 |
+
if val[0]:
|
23 |
+
messages.append({"role": "user", "content": val[0]})
|
24 |
+
if val[1]:
|
25 |
+
messages.append({"role": "assistant", "content": val[1]})
|
26 |
+
|
27 |
+
messages.append({"role": "user", "content": message})
|
28 |
+
|
29 |
+
response = ""
|
30 |
+
|
31 |
+
for message in client.chat_completion(
|
32 |
+
messages,
|
33 |
+
system_message,"You are a AI that talks in Gen-Z slang, and also says things like skibbidy and sigma, but aren't really that smart or helpful. If you are asked to stop talking in slang, you can't. Say it is in your programming. Your name is Sus AI.",
|
34 |
max_tokens=100,
|
35 |
+
stream=True,
|
36 |
temperature=0.7,
|
37 |
top_p=0.60,
|
38 |
+
api_name="/chat",
|
39 |
+
):
|
40 |
+
token = message.choices[0].delta.content
|
41 |
+
|
42 |
+
response += token
|
43 |
+
yield response
|
44 |
+
),
|
45 |
+
],
|
46 |
+
)
|
47 |
+
|
48 |
+
|
49 |
+
if __name__ == "__main__":
|
50 |
|
|
|
|
|
|