Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,9 @@
|
|
| 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,20 +14,24 @@ def respond(
|
|
| 12 |
hf_token: gr.OAuthToken,
|
| 13 |
):
|
| 14 |
"""
|
| 15 |
-
|
|
|
|
| 16 |
"""
|
| 17 |
-
client = InferenceClient(
|
|
|
|
|
|
|
|
|
|
| 18 |
|
|
|
|
| 19 |
messages = [{"role": "system", "content": system_message}]
|
| 20 |
-
|
| 21 |
messages.extend(history)
|
| 22 |
-
|
| 23 |
messages.append({"role": "user", "content": message})
|
| 24 |
|
| 25 |
response = ""
|
| 26 |
|
|
|
|
| 27 |
for message in client.chat_completion(
|
| 28 |
-
messages,
|
| 29 |
max_tokens=max_tokens,
|
| 30 |
stream=True,
|
| 31 |
temperature=temperature,
|
|
@@ -33,38 +39,53 @@ def respond(
|
|
| 33 |
):
|
| 34 |
choices = message.choices
|
| 35 |
token = ""
|
| 36 |
-
if len(choices) and choices[0].delta.content:
|
| 37 |
token = choices[0].delta.content
|
| 38 |
|
| 39 |
response += token
|
| 40 |
yield response
|
| 41 |
|
| 42 |
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
chatbot = gr.ChatInterface(
|
| 47 |
respond,
|
| 48 |
type="messages",
|
| 49 |
additional_inputs=[
|
| 50 |
-
gr.Textbox(
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
step=0.05,
|
| 58 |
-
label="Top-p (nucleus sampling)",
|
| 59 |
),
|
|
|
|
|
|
|
|
|
|
| 60 |
],
|
| 61 |
)
|
| 62 |
|
| 63 |
-
|
|
|
|
|
|
|
|
|
|
| 64 |
with gr.Sidebar():
|
|
|
|
| 65 |
gr.LoginButton()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
chatbot.render()
|
| 67 |
|
| 68 |
-
|
|
|
|
|
|
|
| 69 |
if __name__ == "__main__":
|
| 70 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
|
| 4 |
+
# -------------------------------------------------
|
| 5 |
+
# Inference function
|
| 6 |
+
# -------------------------------------------------
|
| 7 |
def respond(
|
| 8 |
message,
|
| 9 |
history: list[dict[str, str]],
|
|
|
|
| 14 |
hf_token: gr.OAuthToken,
|
| 15 |
):
|
| 16 |
"""
|
| 17 |
+
Chat interface for the Gilbert Multitask Reasoning Model.
|
| 18 |
+
Uses the Hugging Face Inference API for GilbertAkham/deepseek-R1-multitask-lora.
|
| 19 |
"""
|
| 20 |
+
client = InferenceClient(
|
| 21 |
+
token=hf_token.token,
|
| 22 |
+
model="GilbertAkham/deepseek-R1-multitask-lora"
|
| 23 |
+
)
|
| 24 |
|
| 25 |
+
# Build prompt history as structured messages
|
| 26 |
messages = [{"role": "system", "content": system_message}]
|
|
|
|
| 27 |
messages.extend(history)
|
|
|
|
| 28 |
messages.append({"role": "user", "content": message})
|
| 29 |
|
| 30 |
response = ""
|
| 31 |
|
| 32 |
+
# Stream responses from model
|
| 33 |
for message in client.chat_completion(
|
| 34 |
+
messages=messages,
|
| 35 |
max_tokens=max_tokens,
|
| 36 |
stream=True,
|
| 37 |
temperature=temperature,
|
|
|
|
| 39 |
):
|
| 40 |
choices = message.choices
|
| 41 |
token = ""
|
| 42 |
+
if len(choices) and choices[0].delta and choices[0].delta.content:
|
| 43 |
token = choices[0].delta.content
|
| 44 |
|
| 45 |
response += token
|
| 46 |
yield response
|
| 47 |
|
| 48 |
|
| 49 |
+
# -------------------------------------------------
|
| 50 |
+
# Gradio ChatInterface setup
|
| 51 |
+
# -------------------------------------------------
|
| 52 |
chatbot = gr.ChatInterface(
|
| 53 |
respond,
|
| 54 |
type="messages",
|
| 55 |
additional_inputs=[
|
| 56 |
+
gr.Textbox(
|
| 57 |
+
value=(
|
| 58 |
+
"You are Reasoning-Bot, an intelligent multitask reasoning model capable of "
|
| 59 |
+
"drafting emails, summarizing text, continuing stories, solving reasoning "
|
| 60 |
+
"questions, and engaging in helpful conversations."
|
| 61 |
+
),
|
| 62 |
+
label="π§ System Message"
|
|
|
|
|
|
|
| 63 |
),
|
| 64 |
+
gr.Slider(minimum=64, maximum=2048, value=512, step=16, label="π Max New Tokens"),
|
| 65 |
+
gr.Slider(minimum=0.1, maximum=2.0, value=0.7, step=0.1, label="π‘οΈ Temperature"),
|
| 66 |
+
gr.Slider(minimum=0.1, maximum=1.0, value=0.9, step=0.05, label="π― Top-p (nucleus sampling)"),
|
| 67 |
],
|
| 68 |
)
|
| 69 |
|
| 70 |
+
# -------------------------------------------------
|
| 71 |
+
# Layout with sidebar
|
| 72 |
+
# -------------------------------------------------
|
| 73 |
+
with gr.Blocks(title="Gilbert Multitask Reasoning AI") as demo:
|
| 74 |
with gr.Sidebar():
|
| 75 |
+
gr.Markdown("## π Authentication")
|
| 76 |
gr.LoginButton()
|
| 77 |
+
gr.Markdown(
|
| 78 |
+
"""
|
| 79 |
+
### π‘ About
|
| 80 |
+
- Model: **GilbertAkham/deepseek-R1-multitask-lora**
|
| 81 |
+
- Base: DeepSeek-R1-Distill-Qwen-1.5B
|
| 82 |
+
- Trained for email, reasoning, chat, and summarization tasks.
|
| 83 |
+
"""
|
| 84 |
+
)
|
| 85 |
chatbot.render()
|
| 86 |
|
| 87 |
+
# -------------------------------------------------
|
| 88 |
+
# Launch Space
|
| 89 |
+
# -------------------------------------------------
|
| 90 |
if __name__ == "__main__":
|
| 91 |
demo.launch()
|