Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,9 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
def respond(
|
| 5 |
message,
|
|
@@ -9,18 +13,16 @@ def respond(
|
|
| 9 |
temperature,
|
| 10 |
top_p,
|
| 11 |
):
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
client = InferenceClient(model="openai/gpt-oss-20b")
|
| 17 |
|
| 18 |
messages = [{"role": "system", "content": system_message}]
|
| 19 |
messages.extend(history)
|
| 20 |
messages.append({"role": "user", "content": message})
|
| 21 |
|
| 22 |
response = ""
|
| 23 |
-
|
| 24 |
for msg in client.chat_completion(
|
| 25 |
messages,
|
| 26 |
max_tokens=max_tokens,
|
|
@@ -29,15 +31,11 @@ def respond(
|
|
| 29 |
top_p=top_p,
|
| 30 |
):
|
| 31 |
choices = msg.choices
|
| 32 |
-
token = ""
|
| 33 |
if len(choices) and choices[0].delta.content:
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
response += token
|
| 37 |
yield response
|
| 38 |
|
| 39 |
|
| 40 |
-
# Chatbot Interface without Login
|
| 41 |
chatbot = gr.ChatInterface(
|
| 42 |
respond,
|
| 43 |
type="messages",
|
|
@@ -55,6 +53,5 @@ chatbot = gr.ChatInterface(
|
|
| 55 |
],
|
| 56 |
)
|
| 57 |
|
| 58 |
-
# Directly launch chatbot
|
| 59 |
if __name__ == "__main__":
|
| 60 |
-
chatbot.launch()
|
|
|
|
| 1 |
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 |
message,
|
|
|
|
| 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})
|
| 24 |
|
| 25 |
response = ""
|
|
|
|
| 26 |
for msg in client.chat_completion(
|
| 27 |
messages,
|
| 28 |
max_tokens=max_tokens,
|
|
|
|
| 31 |
top_p=top_p,
|
| 32 |
):
|
| 33 |
choices = msg.choices
|
|
|
|
| 34 |
if len(choices) and choices[0].delta.content:
|
| 35 |
+
response += choices[0].delta.content
|
|
|
|
|
|
|
| 36 |
yield response
|
| 37 |
|
| 38 |
|
|
|
|
| 39 |
chatbot = gr.ChatInterface(
|
| 40 |
respond,
|
| 41 |
type="messages",
|
|
|
|
| 53 |
],
|
| 54 |
)
|
| 55 |
|
|
|
|
| 56 |
if __name__ == "__main__":
|
| 57 |
+
chatbot.launch(share=True)
|