aimanathar commited on
Commit
c0028c4
·
verified ·
1 Parent(s): 050ed4c

Update app.py

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