vedarshatarun69 commited on
Commit
7997e4f
·
verified ·
1 Parent(s): 6a031ab

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -13
app.py CHANGED
@@ -1,28 +1,25 @@
1
  import gradio as gr
2
- import requests
3
 
4
- API_URL = "https://api-inference.huggingface.co/models/google/flan-t5-small"
5
- # You can leave headers empty if model is public
6
- headers = {}
7
 
8
  def chat(message, history=[]):
9
- payload = {"inputs": message}
10
- try:
11
- response = requests.post(API_URL, headers=headers, json=payload, timeout=30)
12
- result = response.json()
13
- reply = result[0]['generated_text']
14
- except Exception as e:
15
- reply = f"⚠️ Error: {str(e)}"
16
  history.append((message, reply))
17
  return history, history
18
 
19
  with gr.Blocks() as demo:
20
- gr.Markdown("## 🤖 Permanent AI Chatbot (CPU-Friendly)")
21
  chat_ui = gr.Chatbot()
22
- msg = gr.Textbox(label="Type your message")
23
  clear = gr.Button("Clear Chat")
24
 
25
  msg.submit(chat, [msg, chat_ui], [chat_ui, chat_ui])
26
  clear.click(lambda: None, None, chat_ui, queue=False)
27
 
28
  demo.launch()
 
 
 
 
1
  import gradio as gr
2
+ from transformers import pipeline
3
 
4
+ # Tiny, CPU-friendly model
5
+ chatbot_pipeline = pipeline("text-generation", model="sshleifer/tiny-gpt2")
 
6
 
7
  def chat(message, history=[]):
8
+ result = chatbot_pipeline(message, max_new_tokens=50)
9
+ reply = result[0]['generated_text'].replace(message, "").strip()
 
 
 
 
 
10
  history.append((message, reply))
11
  return history, history
12
 
13
  with gr.Blocks() as demo:
14
+ gr.Markdown("## 🤖 Permanent Tiny AI Chatbot")
15
  chat_ui = gr.Chatbot()
16
+ msg = gr.Textbox(label="Type your message here")
17
  clear = gr.Button("Clear Chat")
18
 
19
  msg.submit(chat, [msg, chat_ui], [chat_ui, chat_ui])
20
  clear.click(lambda: None, None, chat_ui, queue=False)
21
 
22
  demo.launch()
23
+
24
+
25
+