Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,22 +2,10 @@ import gradio as gr
|
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
import os
|
| 4 |
|
| 5 |
-
# Secret from Hugging Face Space settings
|
| 6 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 7 |
|
| 8 |
-
def respond(
|
| 9 |
-
|
| 10 |
-
history: list[dict[str, str]],
|
| 11 |
-
system_message,
|
| 12 |
-
max_tokens,
|
| 13 |
-
temperature,
|
| 14 |
-
top_p,
|
| 15 |
-
):
|
| 16 |
-
client = InferenceClient(
|
| 17 |
-
token=HF_TOKEN, # ab token yahan se aa raha hai
|
| 18 |
-
model="openai/gpt-oss-20b"
|
| 19 |
-
)
|
| 20 |
-
|
| 21 |
messages = [{"role": "system", "content": system_message}]
|
| 22 |
messages.extend(history)
|
| 23 |
messages.append({"role": "user", "content": message})
|
|
@@ -30,28 +18,50 @@ def respond(
|
|
| 30 |
temperature=temperature,
|
| 31 |
top_p=top_p,
|
| 32 |
):
|
| 33 |
-
choices
|
| 34 |
-
|
| 35 |
-
response += choices[0].delta.content
|
| 36 |
yield response
|
| 37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
minimum=0.1,
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
label="Top-p (nucleus sampling)",
|
| 52 |
-
),
|
| 53 |
-
],
|
| 54 |
-
)
|
| 55 |
|
| 56 |
if __name__ == "__main__":
|
| 57 |
-
|
|
|
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
import os
|
| 4 |
|
|
|
|
| 5 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 6 |
|
| 7 |
+
def respond(message, history: list[dict[str, str]], system_message, max_tokens, temperature, top_p):
|
| 8 |
+
client = InferenceClient(token=HF_TOKEN, model="openai/gpt-oss-20b")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
messages = [{"role": "system", "content": system_message}]
|
| 10 |
messages.extend(history)
|
| 11 |
messages.append({"role": "user", "content": message})
|
|
|
|
| 18 |
temperature=temperature,
|
| 19 |
top_p=top_p,
|
| 20 |
):
|
| 21 |
+
if msg.choices and msg.choices[0].delta.content:
|
| 22 |
+
response += msg.choices[0].delta.content
|
|
|
|
| 23 |
yield response
|
| 24 |
|
| 25 |
+
custom_css = """
|
| 26 |
+
.gradio-container {
|
| 27 |
+
background-color: #f9f9fb;
|
| 28 |
+
font-family: Arial, sans-serif;
|
| 29 |
+
}
|
| 30 |
+
.gradio-chatbox .message.user {
|
| 31 |
+
background-color: #daf7dc;
|
| 32 |
+
border-radius: 12px;
|
| 33 |
+
padding: 8px;
|
| 34 |
+
margin: 4px 0;
|
| 35 |
+
}
|
| 36 |
+
.gradio-chatbox .message.bot {
|
| 37 |
+
background-color: #cce5ff;
|
| 38 |
+
border-radius: 12px;
|
| 39 |
+
padding: 8px;
|
| 40 |
+
margin: 4px 0;
|
| 41 |
+
}
|
| 42 |
+
input[type="text"] {
|
| 43 |
+
border-radius: 8px;
|
| 44 |
+
border: 1px solid #ccc;
|
| 45 |
+
}
|
| 46 |
+
button {
|
| 47 |
+
background-color: #007bff;
|
| 48 |
+
color: white;
|
| 49 |
+
border-radius: 8px;
|
| 50 |
+
}
|
| 51 |
+
"""
|
| 52 |
|
| 53 |
+
with gr.Blocks(theme=gr.themes.Soft(), css=custom_css) as demo:
|
| 54 |
+
chatbot = gr.ChatInterface(
|
| 55 |
+
respond,
|
| 56 |
+
type="messages",
|
| 57 |
+
additional_inputs=[
|
| 58 |
+
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
| 59 |
+
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
| 60 |
+
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
| 61 |
+
gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p"),
|
| 62 |
+
]
|
| 63 |
+
)
|
| 64 |
+
chatbot.render()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
|
| 66 |
if __name__ == "__main__":
|
| 67 |
+
demo.launch(share=True)
|