Spaces:
Sleeping
Sleeping
DhanshCOSQ commited on
Commit ·
34d37fe
1
Parent(s): d82214a
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
|
|
|
|
| 4 |
def respond(
|
| 5 |
message,
|
| 6 |
history: list[dict[str, str]],
|
|
@@ -11,36 +12,38 @@ def respond(
|
|
| 11 |
hf_token: gr.OAuthToken,
|
| 12 |
):
|
| 13 |
"""
|
| 14 |
-
|
|
|
|
| 15 |
"""
|
| 16 |
-
client = InferenceClient(
|
| 17 |
-
token=hf_token.token,
|
| 18 |
-
model="Dhansh2001/my-fitlien-chatbot-pruned-quantized"
|
| 19 |
-
)
|
| 20 |
|
| 21 |
-
#
|
| 22 |
-
|
| 23 |
-
|
|
|
|
| 24 |
|
| 25 |
response = ""
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
| 29 |
temperature=temperature,
|
| 30 |
top_p=top_p,
|
| 31 |
-
stream=True,
|
| 32 |
):
|
| 33 |
-
|
| 34 |
-
|
|
|
|
|
|
|
| 35 |
|
| 36 |
|
| 37 |
-
# Build Chat UI
|
| 38 |
chatbot = gr.ChatInterface(
|
| 39 |
respond,
|
| 40 |
type="messages",
|
| 41 |
additional_inputs=[
|
| 42 |
-
gr.Textbox(value="You are a friendly
|
| 43 |
-
gr.Slider(minimum=1, maximum=2048, value=
|
| 44 |
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
| 45 |
gr.Slider(
|
| 46 |
minimum=0.1,
|
|
@@ -57,6 +60,5 @@ with gr.Blocks() as demo:
|
|
| 57 |
gr.LoginButton()
|
| 58 |
chatbot.render()
|
| 59 |
|
| 60 |
-
|
| 61 |
if __name__ == "__main__":
|
| 62 |
-
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
|
| 4 |
+
|
| 5 |
def respond(
|
| 6 |
message,
|
| 7 |
history: list[dict[str, str]],
|
|
|
|
| 12 |
hf_token: gr.OAuthToken,
|
| 13 |
):
|
| 14 |
"""
|
| 15 |
+
For more information on `huggingface_hub` Inference API support, please check:
|
| 16 |
+
https://huggingface.co/docs/huggingface_hub/en/guides/inference
|
| 17 |
"""
|
| 18 |
+
client = InferenceClient(token=hf_token.token, model="openai/gpt-oss-20b")
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
+
# Format messages in Chat API format
|
| 21 |
+
messages = [{"role": "system", "content": system_message}]
|
| 22 |
+
messages.extend(history)
|
| 23 |
+
messages.append({"role": "user", "content": message})
|
| 24 |
|
| 25 |
response = ""
|
| 26 |
+
|
| 27 |
+
# Use chat_completion instead of text_generation
|
| 28 |
+
for event in client.chat_completion(
|
| 29 |
+
messages=messages,
|
| 30 |
+
max_tokens=max_tokens,
|
| 31 |
+
stream=True,
|
| 32 |
temperature=temperature,
|
| 33 |
top_p=top_p,
|
|
|
|
| 34 |
):
|
| 35 |
+
if event.choices and event.choices[0].delta.content:
|
| 36 |
+
token = event.choices[0].delta.content
|
| 37 |
+
response += token
|
| 38 |
+
yield response
|
| 39 |
|
| 40 |
|
|
|
|
| 41 |
chatbot = gr.ChatInterface(
|
| 42 |
respond,
|
| 43 |
type="messages",
|
| 44 |
additional_inputs=[
|
| 45 |
+
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
| 46 |
+
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
| 47 |
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
| 48 |
gr.Slider(
|
| 49 |
minimum=0.1,
|
|
|
|
| 60 |
gr.LoginButton()
|
| 61 |
chatbot.render()
|
| 62 |
|
|
|
|
| 63 |
if __name__ == "__main__":
|
| 64 |
+
demo.launch(ssr_mode=False) # disable SSR for stability
|