Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,8 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import InferenceClient
|
3 |
-
import json
|
4 |
|
5 |
-
# Initialize the client
|
6 |
client = InferenceClient(
|
7 |
model="davnas/Italian_Cousine_2.1",
|
8 |
headers={"Content-Type": "application/json"}
|
@@ -10,31 +9,19 @@ client = InferenceClient(
|
|
10 |
|
11 |
def respond(message, history, system_message, max_tokens, temperature, top_p):
|
12 |
# Format the prompt including history and system message
|
13 |
-
|
14 |
|
15 |
# Add system message if provided
|
16 |
if system_message:
|
17 |
-
|
18 |
|
19 |
# Add conversation history
|
20 |
-
for
|
21 |
-
|
22 |
-
|
23 |
|
24 |
# Add current message
|
25 |
-
|
26 |
-
|
27 |
-
# Convert conversation to prompt format
|
28 |
-
prompt = ""
|
29 |
-
for msg in conversation:
|
30 |
-
if msg["role"] == "system":
|
31 |
-
prompt += f"{msg['content']}\n"
|
32 |
-
elif msg["role"] == "user":
|
33 |
-
prompt += f"User: {msg['content']}\n"
|
34 |
-
elif msg["role"] == "assistant":
|
35 |
-
prompt += f"Assistant: {msg['content']}\n"
|
36 |
-
|
37 |
-
prompt += "Assistant:"
|
38 |
|
39 |
# Prepare parameters for text generation
|
40 |
parameters = {
|
@@ -57,7 +44,7 @@ def respond(message, history, system_message, max_tokens, temperature, top_p):
|
|
57 |
except Exception as e:
|
58 |
yield f"Error: {str(e)}"
|
59 |
|
60 |
-
# Create the interface
|
61 |
demo = gr.ChatInterface(
|
62 |
respond,
|
63 |
additional_inputs=[
|
@@ -86,8 +73,7 @@ demo = gr.ChatInterface(
|
|
86 |
step=0.05,
|
87 |
label="Top-p (nucleus sampling)"
|
88 |
),
|
89 |
-
]
|
90 |
-
chatbot=gr.Chatbot(type="messages") # Use messages format instead of tuples
|
91 |
)
|
92 |
|
93 |
if __name__ == "__main__":
|
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import InferenceClient
|
|
|
3 |
|
4 |
+
# Initialize the client
|
5 |
client = InferenceClient(
|
6 |
model="davnas/Italian_Cousine_2.1",
|
7 |
headers={"Content-Type": "application/json"}
|
|
|
9 |
|
10 |
def respond(message, history, system_message, max_tokens, temperature, top_p):
|
11 |
# Format the prompt including history and system message
|
12 |
+
prompt = ""
|
13 |
|
14 |
# Add system message if provided
|
15 |
if system_message:
|
16 |
+
prompt += f"{system_message}\n"
|
17 |
|
18 |
# Add conversation history
|
19 |
+
for msg in history:
|
20 |
+
if isinstance(msg, list) and len(msg) == 2:
|
21 |
+
prompt += f"User: {msg[0]}\nAssistant: {msg[1]}\n"
|
22 |
|
23 |
# Add current message
|
24 |
+
prompt += f"User: {message}\nAssistant:"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
|
26 |
# Prepare parameters for text generation
|
27 |
parameters = {
|
|
|
44 |
except Exception as e:
|
45 |
yield f"Error: {str(e)}"
|
46 |
|
47 |
+
# Create the interface
|
48 |
demo = gr.ChatInterface(
|
49 |
respond,
|
50 |
additional_inputs=[
|
|
|
73 |
step=0.05,
|
74 |
label="Top-p (nucleus sampling)"
|
75 |
),
|
76 |
+
]
|
|
|
77 |
)
|
78 |
|
79 |
if __name__ == "__main__":
|