Spaces:
Runtime error
Runtime error
Test our model
Browse files
app.py
CHANGED
@@ -62,67 +62,66 @@
|
|
62 |
# if __name__ == "__main__":
|
63 |
# demo.launch()
|
64 |
|
65 |
-
import gradio as gr
|
66 |
-
|
67 |
-
def echo(message, history):
|
68 |
-
return message
|
69 |
-
|
70 |
-
demo = gr.ChatInterface(fn=echo, examples=["hello", "hola", "merhaba"], title="Echo Bot")
|
71 |
-
demo.launch()
|
72 |
-
|
73 |
-
# from huggingface_hub import InferenceClient
|
74 |
# import gradio as gr
|
75 |
|
76 |
-
#
|
77 |
-
#
|
78 |
-
|
79 |
-
# def respond(
|
80 |
-
# message,
|
81 |
-
# history: list[tuple[str, str]],
|
82 |
-
# system_message,
|
83 |
-
# max_tokens,
|
84 |
-
# temperature,
|
85 |
-
# top_p,
|
86 |
-
# ):
|
87 |
-
# messages = [{"role": "system", "content": system_message}]
|
88 |
-
|
89 |
-
# for val in history:
|
90 |
-
# if val[0]:
|
91 |
-
# messages.append({"role": "user", "content": val[0]})
|
92 |
-
# if val[1]:
|
93 |
-
# messages.append({"role": "assistant", "content": val[1]})
|
94 |
-
|
95 |
-
# messages.append({"role": "user", "content": message})
|
96 |
-
|
97 |
-
# response = ""
|
98 |
-
|
99 |
-
# for message in client.chat_completion(
|
100 |
-
# messages,
|
101 |
-
# max_tokens=max_tokens,
|
102 |
-
# stream=True,
|
103 |
-
# temperature=temperature,
|
104 |
-
# top_p=top_p,
|
105 |
-
# ):
|
106 |
-
# token = message.choices[0].delta.content
|
107 |
|
108 |
-
#
|
109 |
-
#
|
110 |
|
111 |
-
|
112 |
-
|
113 |
-
# additional_inputs=[
|
114 |
-
# gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
115 |
-
# gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
116 |
-
# gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
117 |
-
# gr.Slider(
|
118 |
-
# minimum=0.1,
|
119 |
-
# maximum=1.0,
|
120 |
-
# value=0.95,
|
121 |
-
# step=0.05,
|
122 |
-
# label="Top-p (nucleus sampling)",
|
123 |
-
# ),
|
124 |
-
# ],
|
125 |
-
# )
|
126 |
|
127 |
-
|
128 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
# if __name__ == "__main__":
|
63 |
# demo.launch()
|
64 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
# import gradio as gr
|
66 |
|
67 |
+
# def echo(message, history):
|
68 |
+
# return message
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
|
70 |
+
# demo = gr.ChatInterface(fn=echo, examples=["hello", "hola", "merhaba"], title="Echo Bot")
|
71 |
+
# demo.launch()
|
72 |
|
73 |
+
from huggingface_hub import InferenceClient
|
74 |
+
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
|
76 |
+
client = InferenceClient("Aragoner/OrpoLlama-3-8B")
|
77 |
+
|
78 |
+
def respond(
|
79 |
+
message,
|
80 |
+
history: list[tuple[str, str]],
|
81 |
+
system_message,
|
82 |
+
max_tokens,
|
83 |
+
temperature,
|
84 |
+
top_p,
|
85 |
+
):
|
86 |
+
messages = [{"role": "system", "content": system_message}]
|
87 |
+
|
88 |
+
for val in history:
|
89 |
+
if val[0]:
|
90 |
+
messages.append({"role": "user", "content": val[0]})
|
91 |
+
if val[1]:
|
92 |
+
messages.append({"role": "assistant", "content": val[1]})
|
93 |
+
|
94 |
+
messages.append({"role": "user", "content": message})
|
95 |
+
|
96 |
+
response = ""
|
97 |
+
|
98 |
+
for message in client.chat_completion(
|
99 |
+
messages,
|
100 |
+
max_tokens=max_tokens,
|
101 |
+
stream=True,
|
102 |
+
temperature=temperature,
|
103 |
+
top_p=top_p,
|
104 |
+
):
|
105 |
+
token = message.choices[0].delta.content
|
106 |
+
|
107 |
+
response += token
|
108 |
+
yield response
|
109 |
+
|
110 |
+
demo = gr.ChatInterface(
|
111 |
+
respond,
|
112 |
+
additional_inputs=[
|
113 |
+
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
114 |
+
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
115 |
+
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
116 |
+
gr.Slider(
|
117 |
+
minimum=0.1,
|
118 |
+
maximum=1.0,
|
119 |
+
value=0.95,
|
120 |
+
step=0.05,
|
121 |
+
label="Top-p (nucleus sampling)",
|
122 |
+
),
|
123 |
+
],
|
124 |
+
)
|
125 |
+
|
126 |
+
if __name__ == "__main__":
|
127 |
+
demo.launch()
|