Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -46,7 +46,7 @@ import gradio as gr
|
|
46 |
from huggingface_hub import InferenceClient
|
47 |
import os
|
48 |
|
49 |
-
hf_token = os.getenv("HF_TOKEN")
|
50 |
|
51 |
client = InferenceClient("google/gemma-2-2b-it")
|
52 |
|
@@ -54,13 +54,14 @@ def respond(
|
|
54 |
message,
|
55 |
history: list[tuple[str, str]],
|
56 |
#system_message,
|
57 |
-
user_message,
|
58 |
max_tokens,
|
59 |
temperature,
|
60 |
top_p,
|
61 |
):
|
62 |
#messages = [{"role": "system", "content": system_message}]
|
63 |
-
messages = [{"role": "user", "content": user_message}]
|
|
|
64 |
|
65 |
for val in history:
|
66 |
if val[0]:
|
@@ -75,32 +76,22 @@ def respond(
|
|
75 |
for message in client.chat_completion(
|
76 |
messages,
|
77 |
max_tokens=max_tokens,
|
78 |
-
stream=True,
|
79 |
temperature=temperature,
|
80 |
top_p=top_p,
|
|
|
81 |
):
|
82 |
token = message.choices[0].delta.content
|
83 |
|
84 |
response += token
|
85 |
yield response
|
86 |
|
87 |
-
|
88 |
-
"""
|
89 |
-
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
90 |
-
"""
|
91 |
demo = gr.ChatInterface(
|
92 |
respond,
|
93 |
additional_inputs=[
|
94 |
-
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
95 |
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
96 |
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
97 |
-
gr.Slider(
|
98 |
-
minimum=0.1,
|
99 |
-
maximum=1.0,
|
100 |
-
value=0.95,
|
101 |
-
step=0.05,
|
102 |
-
label="Top-p (nucleus sampling)",
|
103 |
-
),
|
104 |
],
|
105 |
)
|
106 |
|
|
|
46 |
from huggingface_hub import InferenceClient
|
47 |
import os
|
48 |
|
49 |
+
#hf_token = os.getenv("HF_TOKEN")
|
50 |
|
51 |
client = InferenceClient("google/gemma-2-2b-it")
|
52 |
|
|
|
54 |
message,
|
55 |
history: list[tuple[str, str]],
|
56 |
#system_message,
|
57 |
+
##user_message,
|
58 |
max_tokens,
|
59 |
temperature,
|
60 |
top_p,
|
61 |
):
|
62 |
#messages = [{"role": "system", "content": system_message}]
|
63 |
+
##messages = [{"role": "user", "content": user_message}]
|
64 |
+
messages = []
|
65 |
|
66 |
for val in history:
|
67 |
if val[0]:
|
|
|
76 |
for message in client.chat_completion(
|
77 |
messages,
|
78 |
max_tokens=max_tokens,
|
|
|
79 |
temperature=temperature,
|
80 |
top_p=top_p,
|
81 |
+
stream=True,
|
82 |
):
|
83 |
token = message.choices[0].delta.content
|
84 |
|
85 |
response += token
|
86 |
yield response
|
87 |
|
|
|
|
|
|
|
|
|
88 |
demo = gr.ChatInterface(
|
89 |
respond,
|
90 |
additional_inputs=[
|
91 |
+
#gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
92 |
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
93 |
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
94 |
+
gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)"),
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
],
|
96 |
)
|
97 |
|