Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,6 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
|
| 4 |
-
|
| 5 |
def respond(
|
| 6 |
message,
|
| 7 |
history: list[dict[str, str]],
|
|
@@ -9,29 +8,27 @@ def respond(
|
|
| 9 |
max_tokens,
|
| 10 |
temperature,
|
| 11 |
top_p,
|
| 12 |
-
hf_token: gr.OAuthToken,
|
| 13 |
):
|
| 14 |
"""
|
| 15 |
-
|
| 16 |
"""
|
| 17 |
-
|
|
|
|
| 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
|
| 28 |
messages,
|
| 29 |
max_tokens=max_tokens,
|
| 30 |
stream=True,
|
| 31 |
temperature=temperature,
|
| 32 |
top_p=top_p,
|
| 33 |
):
|
| 34 |
-
choices =
|
| 35 |
token = ""
|
| 36 |
if len(choices) and choices[0].delta.content:
|
| 37 |
token = choices[0].delta.content
|
|
@@ -40,9 +37,7 @@ def respond(
|
|
| 40 |
yield response
|
| 41 |
|
| 42 |
|
| 43 |
-
|
| 44 |
-
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
| 45 |
-
"""
|
| 46 |
chatbot = gr.ChatInterface(
|
| 47 |
respond,
|
| 48 |
type="messages",
|
|
@@ -60,11 +55,6 @@ chatbot = gr.ChatInterface(
|
|
| 60 |
],
|
| 61 |
)
|
| 62 |
|
| 63 |
-
|
| 64 |
-
with gr.Sidebar():
|
| 65 |
-
gr.LoginButton()
|
| 66 |
-
chatbot.render()
|
| 67 |
-
|
| 68 |
-
|
| 69 |
if __name__ == "__main__":
|
| 70 |
-
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
|
|
|
|
| 4 |
def respond(
|
| 5 |
message,
|
| 6 |
history: list[dict[str, str]],
|
|
|
|
| 8 |
max_tokens,
|
| 9 |
temperature,
|
| 10 |
top_p,
|
|
|
|
| 11 |
):
|
| 12 |
"""
|
| 13 |
+
Simple chatbot using Hugging Face Inference API
|
| 14 |
"""
|
| 15 |
+
# apna Hugging Face model choose karo
|
| 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,
|
| 27 |
stream=True,
|
| 28 |
temperature=temperature,
|
| 29 |
top_p=top_p,
|
| 30 |
):
|
| 31 |
+
choices = msg.choices
|
| 32 |
token = ""
|
| 33 |
if len(choices) and choices[0].delta.content:
|
| 34 |
token = choices[0].delta.content
|
|
|
|
| 37 |
yield response
|
| 38 |
|
| 39 |
|
| 40 |
+
# Chatbot Interface without Login
|
|
|
|
|
|
|
| 41 |
chatbot = gr.ChatInterface(
|
| 42 |
respond,
|
| 43 |
type="messages",
|
|
|
|
| 55 |
],
|
| 56 |
)
|
| 57 |
|
| 58 |
+
# Directly launch chatbot
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
if __name__ == "__main__":
|
| 60 |
+
chatbot.launch()
|