Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,30 +1,26 @@
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import InferenceClient
|
3 |
|
|
|
4 |
client = InferenceClient("davnas/Italian_Cousine_2.1")
|
5 |
|
6 |
-
def respond(
|
7 |
-
message
|
8 |
-
|
9 |
-
system_message,
|
10 |
-
max_tokens,
|
11 |
-
temperature,
|
12 |
-
top_p,
|
13 |
-
):
|
14 |
-
# Format the prompt in the way your working Colab example does
|
15 |
-
prompt = f"User: {message}\nAssistant:"
|
16 |
|
17 |
-
#
|
|
|
|
|
|
|
|
|
18 |
for user_msg, assistant_msg in history:
|
19 |
-
prompt
|
20 |
|
21 |
-
#
|
22 |
-
|
23 |
-
prompt = f"{system_message}\n" + prompt
|
24 |
-
|
25 |
-
response = ""
|
26 |
|
27 |
-
|
|
|
28 |
for token in client.text_generation(
|
29 |
prompt,
|
30 |
max_new_tokens=max_tokens,
|
@@ -35,20 +31,36 @@ def respond(
|
|
35 |
response += token
|
36 |
yield response
|
37 |
|
|
|
38 |
demo = gr.ChatInterface(
|
39 |
respond,
|
40 |
additional_inputs=[
|
41 |
-
gr.Textbox(
|
42 |
-
|
43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
gr.Slider(
|
45 |
minimum=0.1,
|
46 |
maximum=1.0,
|
47 |
value=0.95,
|
48 |
step=0.05,
|
49 |
-
label="Top-p (nucleus sampling)"
|
50 |
),
|
51 |
-
]
|
52 |
)
|
53 |
|
54 |
if __name__ == "__main__":
|
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import InferenceClient
|
3 |
|
4 |
+
# Initialize the client
|
5 |
client = InferenceClient("davnas/Italian_Cousine_2.1")
|
6 |
|
7 |
+
def respond(message, history: list[tuple[str, str]], system_message, max_tokens, temperature, top_p):
|
8 |
+
# Format the prompt including history and system message
|
9 |
+
prompt = ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
+
# Add system message if provided
|
12 |
+
if system_message:
|
13 |
+
prompt = f"{system_message}\n"
|
14 |
+
|
15 |
+
# Add conversation history
|
16 |
for user_msg, assistant_msg in history:
|
17 |
+
prompt += f"User: {user_msg}\nAssistant: {assistant_msg}\n"
|
18 |
|
19 |
+
# Add current message
|
20 |
+
prompt += f"User: {message}\nAssistant:"
|
|
|
|
|
|
|
21 |
|
22 |
+
response = ""
|
23 |
+
# Stream the response
|
24 |
for token in client.text_generation(
|
25 |
prompt,
|
26 |
max_new_tokens=max_tokens,
|
|
|
31 |
response += token
|
32 |
yield response
|
33 |
|
34 |
+
# Create the interface
|
35 |
demo = gr.ChatInterface(
|
36 |
respond,
|
37 |
additional_inputs=[
|
38 |
+
gr.Textbox(
|
39 |
+
value="You are a friendly Chatbot.",
|
40 |
+
label="System message"
|
41 |
+
),
|
42 |
+
gr.Slider(
|
43 |
+
minimum=1,
|
44 |
+
maximum=2048,
|
45 |
+
value=512,
|
46 |
+
step=1,
|
47 |
+
label="Max new tokens"
|
48 |
+
),
|
49 |
+
gr.Slider(
|
50 |
+
minimum=0.1,
|
51 |
+
maximum=4.0,
|
52 |
+
value=0.7,
|
53 |
+
step=0.1,
|
54 |
+
label="Temperature"
|
55 |
+
),
|
56 |
gr.Slider(
|
57 |
minimum=0.1,
|
58 |
maximum=1.0,
|
59 |
value=0.95,
|
60 |
step=0.05,
|
61 |
+
label="Top-p (nucleus sampling)"
|
62 |
),
|
63 |
+
]
|
64 |
)
|
65 |
|
66 |
if __name__ == "__main__":
|