Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -47,6 +47,65 @@ from huggingface_hub import InferenceClient
|
|
47 |
import os
|
48 |
|
49 |
hf_token = os.getenv("HF_TOKEN")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
client = InferenceClient(api_key=hf_token)
|
51 |
|
52 |
def fn(prompt, history=[]):
|
@@ -81,4 +140,5 @@ app = gr.Interface(
|
|
81 |
examples = [
|
82 |
["Hello, World."]
|
83 |
]
|
84 |
-
).launch()
|
|
|
|
47 |
import os
|
48 |
|
49 |
hf_token = os.getenv("HF_TOKEN")
|
50 |
+
|
51 |
+
client = InferenceClient("google/gemma-2-2b-it")
|
52 |
+
|
53 |
+
def respond(
|
54 |
+
message,
|
55 |
+
history: list[tuple[str, str]],
|
56 |
+
system_message,
|
57 |
+
max_tokens,
|
58 |
+
temperature,
|
59 |
+
top_p,
|
60 |
+
):
|
61 |
+
messages = [{"role": "system", "content": system_message}]
|
62 |
+
|
63 |
+
for val in history:
|
64 |
+
if val[0]:
|
65 |
+
messages.append({"role": "user", "content": val[0]})
|
66 |
+
if val[1]:
|
67 |
+
messages.append({"role": "assistant", "content": val[1]})
|
68 |
+
|
69 |
+
messages.append({"role": "user", "content": message})
|
70 |
+
|
71 |
+
response = ""
|
72 |
+
|
73 |
+
for message in client.chat_completion(
|
74 |
+
messages,
|
75 |
+
max_tokens=max_tokens,
|
76 |
+
stream=True,
|
77 |
+
temperature=temperature,
|
78 |
+
top_p=top_p,
|
79 |
+
):
|
80 |
+
token = message.choices[0].delta.content
|
81 |
+
|
82 |
+
response += token
|
83 |
+
yield response
|
84 |
+
|
85 |
+
|
86 |
+
"""
|
87 |
+
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
88 |
+
"""
|
89 |
+
demo = gr.ChatInterface(
|
90 |
+
respond,
|
91 |
+
additional_inputs=[
|
92 |
+
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
93 |
+
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
94 |
+
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
95 |
+
gr.Slider(
|
96 |
+
minimum=0.1,
|
97 |
+
maximum=1.0,
|
98 |
+
value=0.95,
|
99 |
+
step=0.05,
|
100 |
+
label="Top-p (nucleus sampling)",
|
101 |
+
),
|
102 |
+
],
|
103 |
+
)
|
104 |
+
|
105 |
+
if __name__ == "__main__":
|
106 |
+
demo.launch()
|
107 |
+
|
108 |
+
"""
|
109 |
client = InferenceClient(api_key=hf_token)
|
110 |
|
111 |
def fn(prompt, history=[]):
|
|
|
140 |
examples = [
|
141 |
["Hello, World."]
|
142 |
]
|
143 |
+
).launch()
|
144 |
+
"""
|