Spaces:
Sleeping
Sleeping
Commit
•
4ed6a86
1
Parent(s):
233c71b
Update app.py
Browse files
app.py
CHANGED
@@ -1,12 +1,8 @@
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import InferenceClient
|
3 |
|
4 |
-
"""
|
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("nouamanetazi/hf-ar-134000")
|
8 |
|
9 |
-
|
10 |
def respond(
|
11 |
message,
|
12 |
history: list[tuple[str, str]],
|
@@ -15,34 +11,30 @@ def respond(
|
|
15 |
temperature,
|
16 |
top_p,
|
17 |
):
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
|
|
27 |
|
28 |
response = ""
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
|
|
33 |
stream=True,
|
34 |
temperature=temperature,
|
35 |
top_p=top_p,
|
36 |
):
|
37 |
-
token = message.choices[0].delta.content
|
38 |
-
|
39 |
response += token
|
40 |
yield response
|
41 |
|
42 |
-
|
43 |
-
"""
|
44 |
-
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
45 |
-
"""
|
46 |
demo = gr.ChatInterface(
|
47 |
respond,
|
48 |
additional_inputs=[
|
@@ -59,6 +51,5 @@ demo = gr.ChatInterface(
|
|
59 |
],
|
60 |
)
|
61 |
|
62 |
-
|
63 |
if __name__ == "__main__":
|
64 |
-
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import InferenceClient
|
3 |
|
|
|
|
|
|
|
4 |
client = InferenceClient("nouamanetazi/hf-ar-134000")
|
5 |
|
|
|
6 |
def respond(
|
7 |
message,
|
8 |
history: list[tuple[str, str]],
|
|
|
11 |
temperature,
|
12 |
top_p,
|
13 |
):
|
14 |
+
# Combine history and new message into a single prompt
|
15 |
+
prompt = system_message + "\n\n"
|
16 |
+
|
17 |
+
for user_msg, assistant_msg in history:
|
18 |
+
if user_msg:
|
19 |
+
prompt += f"User: {user_msg}\n"
|
20 |
+
if assistant_msg:
|
21 |
+
prompt += f"Assistant: {assistant_msg}\n"
|
22 |
+
|
23 |
+
prompt += f"User: {message}\nAssistant:"
|
24 |
|
25 |
response = ""
|
26 |
+
|
27 |
+
# Use text-generation instead of chat_completion
|
28 |
+
for token in client.text_generation(
|
29 |
+
prompt,
|
30 |
+
max_new_tokens=max_tokens,
|
31 |
stream=True,
|
32 |
temperature=temperature,
|
33 |
top_p=top_p,
|
34 |
):
|
|
|
|
|
35 |
response += token
|
36 |
yield response
|
37 |
|
|
|
|
|
|
|
|
|
38 |
demo = gr.ChatInterface(
|
39 |
respond,
|
40 |
additional_inputs=[
|
|
|
51 |
],
|
52 |
)
|
53 |
|
|
|
54 |
if __name__ == "__main__":
|
55 |
+
demo.launch()
|