Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,12 +1,25 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from huggingface_hub import InferenceClient
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 6 |
+
|
| 7 |
+
def respond(message, history):
|
| 8 |
+
client = InferenceClient(token=HF_TOKEN, model="openai/gpt-oss-20b")
|
| 9 |
+
messages = [{"role": "system", "content": "You are a friendly chatbot."}]
|
| 10 |
+
for h in history:
|
| 11 |
+
messages.append({"role": "user", "content": h[0]})
|
| 12 |
+
messages.append({"role": "assistant", "content": h[1]})
|
| 13 |
+
messages.append({"role": "user", "content": message})
|
| 14 |
+
|
| 15 |
+
response = ""
|
| 16 |
+
for msg in client.chat_completion(messages, max_tokens=200, stream=True):
|
| 17 |
+
if msg.choices and msg.choices[0].delta.content:
|
| 18 |
+
response += msg.choices[0].delta.content
|
| 19 |
+
return response
|
| 20 |
+
|
| 21 |
+
# 👇 is tarah karo taake API endpoint expose ho
|
| 22 |
+
demo = gr.ChatInterface(respond)
|
| 23 |
+
|
| 24 |
+
if __name__ == "__main__":
|
| 25 |
+
demo.launch()
|