Shankarm08 commited on
Commit
39172b7
Β·
verified Β·
1 Parent(s): df82699
Files changed (1) hide show
  1. app.py +10 -6
app.py CHANGED
@@ -1,21 +1,25 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
- # -------- TEXT MODEL (LIGHT + SAFE) --------
5
  text_model = pipeline("text-generation", model="distilgpt2")
6
 
7
- # -------- SIMPLE FUNCTION --------
8
  def respond(user_input, history):
9
- # text response only (no crashes)
10
  result = text_model(user_input, max_length=80)[0]["generated_text"]
11
- history.append((user_input, result))
 
 
 
 
 
12
  return history, history
13
 
14
  # -------- UI --------
15
  with gr.Blocks() as demo:
16
- gr.Markdown("# Simple AI Chat (Stable Version)")
17
 
18
- chatbot = gr.Chatbot()
19
  state = gr.State([])
20
 
21
  with gr.Row():
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
+ # -------- MODEL --------
5
  text_model = pipeline("text-generation", model="distilgpt2")
6
 
7
+ # -------- FUNCTION --------
8
  def respond(user_input, history):
 
9
  result = text_model(user_input, max_length=80)[0]["generated_text"]
10
+
11
+ history = history + [
12
+ {"role": "user", "content": user_input},
13
+ {"role": "assistant", "content": result}
14
+ ]
15
+
16
  return history, history
17
 
18
  # -------- UI --------
19
  with gr.Blocks() as demo:
20
+ gr.Markdown("# Simple AI Chat (Fixed)")
21
 
22
+ chatbot = gr.Chatbot(type="messages") # βœ… IMPORTANT
23
  state = gr.State([])
24
 
25
  with gr.Row():