aimanathar commited on
Commit
d8e8a49
·
verified ·
1 Parent(s): 5794ac3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -12
app.py CHANGED
@@ -1,12 +1,25 @@
1
- async function sendMessageToBot(message, history = []) {
2
- let response = await fetch("https://aimanathar-aima-chatbot.hf.space/run/predict", {
3
- method: "POST",
4
- headers: { "Content-Type": "application/json" },
5
- body: JSON.stringify({ data: [message, history] })
6
- });
7
-
8
- let result = await response.json();
9
- console.log("Bot API Response:", result);
10
-
11
- return result.data[0]; // bot ka jawab
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()