Spaces:
Runtime error
Runtime error
Canstralian
commited on
Commit
•
b71bc0f
1
Parent(s):
6786b93
Update app.py
Browse files
app.py
CHANGED
@@ -1,23 +1,26 @@
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import InferenceClient
|
3 |
|
4 |
-
|
|
|
5 |
|
6 |
def respond(message, history, system_message, max_tokens, temperature, top_p):
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
|
|
|
|
12 |
response = ""
|
13 |
-
for
|
14 |
-
|
15 |
):
|
16 |
-
token =
|
17 |
response += token
|
18 |
yield response
|
19 |
|
20 |
-
#
|
21 |
demo = gr.ChatInterface(
|
22 |
respond,
|
23 |
additional_inputs=[
|
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import InferenceClient
|
3 |
|
4 |
+
# Use the specified model for inference
|
5 |
+
client = InferenceClient("canstralian/rabbit-redux")
|
6 |
|
7 |
def respond(message, history, system_message, max_tokens, temperature, top_p):
|
8 |
+
# Construct a single prompt from the system message, history, and current user message
|
9 |
+
prompt = system_message + "\n"
|
10 |
+
for user_msg, assistant_msg in history:
|
11 |
+
prompt += f"User: {user_msg}\nAssistant: {assistant_msg}\n"
|
12 |
+
prompt += f"User: {message}\nAssistant:"
|
13 |
+
|
14 |
+
# Generate the response
|
15 |
response = ""
|
16 |
+
for output in client.text_generation(
|
17 |
+
prompt, max_tokens=max_tokens, temperature=temperature, top_p=top_p, stream=True
|
18 |
):
|
19 |
+
token = output.token.text
|
20 |
response += token
|
21 |
yield response
|
22 |
|
23 |
+
# Set up the Gradio interface
|
24 |
demo = gr.ChatInterface(
|
25 |
respond,
|
26 |
additional_inputs=[
|