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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -36
app.py CHANGED
@@ -1,39 +1,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: list[dict[str, str]]):
8
- client = InferenceClient(token=HF_TOKEN, model="openai/gpt-oss-20b")
9
-
10
- messages = [{"role": "system", "content": "You are a friendly chatbot."}]
11
- messages.extend(history)
12
- messages.append({"role": "user", "content": message})
13
-
14
- response = ""
15
- for msg in client.chat_completion(
16
- messages,
17
- max_tokens=512,
18
- stream=True,
19
- temperature=0.7,
20
- top_p=0.95
21
- ):
22
- if msg.choices and msg.choices[0].delta.content:
23
- response += msg.choices[0].delta.content
24
- yield response
25
-
26
-
27
- # Purple + White/Grey Theme CSS
28
- custom_css = """
29
- .gradio-container {
30
- background: linear-gradient(to bottom right, #7E498B, #f5f5f5);
31
- font-family: 'Segoe UI', sans-serif;
32
  }
33
- """
34
-
35
- with gr.Blocks(theme=gr.themes.Soft(), css=custom_css) as demo:
36
- gr.ChatInterface(respond, type="messages")
37
-
38
- if __name__ == "__main__":
39
- demo.launch(share=True)
 
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
  }