Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,43 +1,41 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
|
|
|
|
| 3 |
|
|
|
|
|
|
|
| 4 |
|
| 5 |
def respond(
|
| 6 |
message,
|
| 7 |
history: list[dict[str, str]],
|
| 8 |
system_message,
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
|
|
|
| 13 |
):
|
| 14 |
-
"""
|
| 15 |
-
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
| 16 |
-
"""
|
| 17 |
-
client = InferenceClient(token=hf_token.token, model="openai/gpt-oss-20b")
|
| 18 |
|
| 19 |
-
|
| 20 |
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
-
|
| 24 |
|
| 25 |
-
|
| 26 |
|
| 27 |
-
|
| 28 |
-
messages,
|
| 29 |
-
max_tokens=max_tokens,
|
| 30 |
-
stream=True,
|
| 31 |
-
temperature=temperature,
|
| 32 |
-
top_p=top_p,
|
| 33 |
-
):
|
| 34 |
-
choices = message.choices
|
| 35 |
-
token = ""
|
| 36 |
-
if len(choices) and choices[0].delta.content:
|
| 37 |
-
token = choices[0].delta.content
|
| 38 |
|
| 39 |
-
|
| 40 |
-
yield response
|
| 41 |
|
| 42 |
|
| 43 |
"""
|
|
@@ -47,23 +45,23 @@ chatbot = gr.ChatInterface(
|
|
| 47 |
respond,
|
| 48 |
type="messages",
|
| 49 |
additional_inputs=[
|
| 50 |
-
gr.Textbox(value="
|
| 51 |
-
gr.
|
| 52 |
-
gr.Slider(minimum=
|
| 53 |
-
gr.Slider(
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
),
|
|
|
|
| 60 |
],
|
| 61 |
)
|
| 62 |
|
| 63 |
with gr.Blocks() as demo:
|
| 64 |
-
with gr.Sidebar():
|
| 65 |
-
gr.LoginButton()
|
| 66 |
chatbot.render()
|
|
|
|
| 67 |
|
| 68 |
|
| 69 |
if __name__ == "__main__":
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import os
|
| 3 |
+
import requests
|
| 4 |
|
| 5 |
+
CHAT_URL = os.getenv("CHAT_URL")
|
| 6 |
+
PROJECT_ID = os.getenv("PROJECT_ID")
|
| 7 |
|
| 8 |
def respond(
|
| 9 |
message,
|
| 10 |
history: list[dict[str, str]],
|
| 11 |
system_message,
|
| 12 |
+
token,
|
| 13 |
+
# max_tokens,
|
| 14 |
+
# temperature,
|
| 15 |
+
# top_p,
|
| 16 |
+
# hf_token: gr.OAuthToken,
|
| 17 |
):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
+
print("[UPDATE VAR]", UPDATE_VAR)
|
| 20 |
|
| 21 |
+
req = requests.post(
|
| 22 |
+
CHAT_URL,
|
| 23 |
+
json={
|
| 24 |
+
"project_id": PROJECT_ID,
|
| 25 |
+
"session_id":system_message,
|
| 26 |
+
"user_input":message,
|
| 27 |
+
"output_variables": ["results"]
|
| 28 |
+
},
|
| 29 |
+
headers={"Authorization" : f"Bearer {token}"}
|
| 30 |
+
)
|
| 31 |
|
| 32 |
+
print("[REQ CONTENT]", req.content)
|
| 33 |
|
| 34 |
+
out = req.json()["data"]["results"]
|
| 35 |
|
| 36 |
+
print("[OUT]",out)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
+
return out.encode('utf-8').decode('unicode_escape')
|
|
|
|
| 39 |
|
| 40 |
|
| 41 |
"""
|
|
|
|
| 45 |
respond,
|
| 46 |
type="messages",
|
| 47 |
additional_inputs=[
|
| 48 |
+
gr.Textbox(value="<TEST_123>", label="session_id"),
|
| 49 |
+
gr.Textbox(value="[TOKEN]", label="token"),
|
| 50 |
+
# gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
| 51 |
+
# gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
| 52 |
+
# gr.Slider(
|
| 53 |
+
# minimum=0.1,
|
| 54 |
+
# maximum=1.0,
|
| 55 |
+
# value=0.95,
|
| 56 |
+
# step=0.05,
|
| 57 |
+
# label="Top-p (nucleus sampling)",
|
| 58 |
+
# ),
|
| 59 |
],
|
| 60 |
)
|
| 61 |
|
| 62 |
with gr.Blocks() as demo:
|
|
|
|
|
|
|
| 63 |
chatbot.render()
|
| 64 |
+
title = gr.HTML("<h3>Use #ai to ask the ai</h3>")
|
| 65 |
|
| 66 |
|
| 67 |
if __name__ == "__main__":
|