Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,12 +1,9 @@
|
|
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("Aksh1t/mistral-7b-oig-unsloth-merged")
|
8 |
|
9 |
-
|
10 |
def respond(
|
11 |
message,
|
12 |
history: list[tuple[str, str]],
|
@@ -17,31 +14,30 @@ def respond(
|
|
17 |
):
|
18 |
messages = [{"role": "system", "content": system_message}]
|
19 |
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
|
|
25 |
|
|
|
26 |
messages.append({"role": "user", "content": message})
|
27 |
|
28 |
-
|
29 |
-
|
30 |
-
for message in client.chat_completion(
|
31 |
messages,
|
32 |
max_tokens=max_tokens,
|
33 |
-
stream=True,
|
34 |
temperature=temperature,
|
35 |
top_p=top_p,
|
36 |
-
)
|
37 |
-
token = message.choices[0].delta.content
|
38 |
|
39 |
-
|
40 |
-
|
|
|
|
|
41 |
|
42 |
-
|
43 |
-
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
44 |
-
"""
|
45 |
demo = gr.ChatInterface(
|
46 |
respond,
|
47 |
additional_inputs=[
|
@@ -58,6 +54,5 @@ demo = gr.ChatInterface(
|
|
58 |
],
|
59 |
)
|
60 |
|
61 |
-
|
62 |
if __name__ == "__main__":
|
63 |
-
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import InferenceClient
|
3 |
|
4 |
+
# Initialize the InferenceClient with your model name
|
|
|
|
|
5 |
client = InferenceClient("Aksh1t/mistral-7b-oig-unsloth-merged")
|
6 |
|
|
|
7 |
def respond(
|
8 |
message,
|
9 |
history: list[tuple[str, str]],
|
|
|
14 |
):
|
15 |
messages = [{"role": "system", "content": system_message}]
|
16 |
|
17 |
+
# Add user and assistant messages from history
|
18 |
+
for user_msg, assistant_msg in history:
|
19 |
+
if user_msg:
|
20 |
+
messages.append({"role": "user", "content": user_msg})
|
21 |
+
if assistant_msg:
|
22 |
+
messages.append({"role": "assistant", "content": assistant_msg})
|
23 |
|
24 |
+
# Add current user message
|
25 |
messages.append({"role": "user", "content": message})
|
26 |
|
27 |
+
# Call the InferenceClient for chat completion
|
28 |
+
response = client.chat_completion(
|
|
|
29 |
messages,
|
30 |
max_tokens=max_tokens,
|
|
|
31 |
temperature=temperature,
|
32 |
top_p=top_p,
|
33 |
+
)
|
|
|
34 |
|
35 |
+
# Extract and yield the assistant's response
|
36 |
+
for message in response:
|
37 |
+
token = message.get("choices")[0].get("delta").get("content")
|
38 |
+
yield token
|
39 |
|
40 |
+
# Create a Gradio interface for the chatbot
|
|
|
|
|
41 |
demo = gr.ChatInterface(
|
42 |
respond,
|
43 |
additional_inputs=[
|
|
|
54 |
],
|
55 |
)
|
56 |
|
|
|
57 |
if __name__ == "__main__":
|
58 |
+
demo.launch()
|