Ram7379 commited on
Commit
c4e54cc
·
verified ·
1 Parent(s): 54fb01d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -9
app.py CHANGED
@@ -1,17 +1,16 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
- # Better model for conversation
5
  chatbot = pipeline(
6
- "text-generation",
7
  model="google/flan-t5-small"
8
  )
9
 
10
  def reply(message, history):
11
  if not message.strip():
12
- return history
13
 
14
- # Instruction-based prompt
15
  prompt = f"User: {message}\nAssistant:"
16
 
17
  result = chatbot(
@@ -23,16 +22,19 @@ def reply(message, history):
23
 
24
  output = result[0]["generated_text"]
25
 
26
- # Extract only assistant reply
27
- response = output.split("Assistant:")[-1].strip()
 
 
 
28
 
29
- history.append((message, response))
30
- return history
31
 
 
32
  demo = gr.ChatInterface(
33
  fn=reply,
34
  title="💬 Smart Dialogue System",
35
- description="Instruction-based chatbot using FLAN-T5"
36
  )
37
 
38
  demo.launch(server_name="0.0.0.0", server_port=7860)
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
+ # Better chatbot model
5
  chatbot = pipeline(
6
+ "text2text-generation",
7
  model="google/flan-t5-small"
8
  )
9
 
10
  def reply(message, history):
11
  if not message.strip():
12
+ return "Please enter a message."
13
 
 
14
  prompt = f"User: {message}\nAssistant:"
15
 
16
  result = chatbot(
 
22
 
23
  output = result[0]["generated_text"]
24
 
25
+ # Extract only assistant response
26
+ if "Assistant:" in output:
27
+ response = output.split("Assistant:")[-1].strip()
28
+ else:
29
+ response = output.strip()
30
 
31
+ return response # ✅ ONLY RETURN STRING
 
32
 
33
+ # Chat UI
34
  demo = gr.ChatInterface(
35
  fn=reply,
36
  title="💬 Smart Dialogue System",
37
+ description="Chatbot using FLAN-T5"
38
  )
39
 
40
  demo.launch(server_name="0.0.0.0", server_port=7860)