kothapallimahitha commited on
Commit
27c51c4
·
verified ·
1 Parent(s): 9f7694a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -7
app.py CHANGED
@@ -1,17 +1,17 @@
1
  import gradio as gr
2
  from transformers import BlenderbotSmallTokenizer, BlenderbotSmallForConditionalGeneration
3
 
4
- # --- Load model and tokenizer ---
5
  model_name = "facebook/blenderbot-90M"
6
  tokenizer = BlenderbotSmallTokenizer.from_pretrained(model_name)
7
  model = BlenderbotSmallForConditionalGeneration.from_pretrained(model_name)
8
 
9
- # --- Define chatbot logic ---
10
  def chat_with_bot(message, history):
11
  if not message:
12
  return "Hi there! 👋 Ask me something to get started."
13
 
14
- # Rebuild conversation context
15
  conversation = ""
16
  if history:
17
  for turn in history:
@@ -24,7 +24,7 @@ def chat_with_bot(message, history):
24
 
25
  conversation += f"User: {message}\nBot:"
26
 
27
- # Tokenize input and generate reply
28
  inputs = tokenizer(
29
  conversation,
30
  return_tensors="pt",
@@ -36,12 +36,12 @@ def chat_with_bot(message, history):
36
  reply = tokenizer.decode(reply_ids[0], skip_special_tokens=True)
37
  return reply
38
 
39
- # --- Define welcome message ---
40
  initial_message = [
41
  {"role": "assistant", "content": "👋 Hello! I’m your chatbot. Ask me anything to start our conversation!"}
42
  ]
43
 
44
- # --- Create Gradio Interface ---
45
  demo = gr.ChatInterface(
46
  fn=chat_with_bot,
47
  title="🤖 Mini Chatbot (Facebook BlenderBot-90M)",
@@ -51,6 +51,6 @@ demo = gr.ChatInterface(
51
  examples=["Hello!", "Tell me a fun fact", "How are you today?"],
52
  )
53
 
54
- # --- Launch App ---
55
  if __name__ == "__main__":
56
  demo.launch(share=True)
 
1
  import gradio as gr
2
  from transformers import BlenderbotSmallTokenizer, BlenderbotSmallForConditionalGeneration
3
 
4
+
5
  model_name = "facebook/blenderbot-90M"
6
  tokenizer = BlenderbotSmallTokenizer.from_pretrained(model_name)
7
  model = BlenderbotSmallForConditionalGeneration.from_pretrained(model_name)
8
 
9
+
10
  def chat_with_bot(message, history):
11
  if not message:
12
  return "Hi there! 👋 Ask me something to get started."
13
 
14
+
15
  conversation = ""
16
  if history:
17
  for turn in history:
 
24
 
25
  conversation += f"User: {message}\nBot:"
26
 
27
+
28
  inputs = tokenizer(
29
  conversation,
30
  return_tensors="pt",
 
36
  reply = tokenizer.decode(reply_ids[0], skip_special_tokens=True)
37
  return reply
38
 
39
+
40
  initial_message = [
41
  {"role": "assistant", "content": "👋 Hello! I’m your chatbot. Ask me anything to start our conversation!"}
42
  ]
43
 
44
+
45
  demo = gr.ChatInterface(
46
  fn=chat_with_bot,
47
  title="🤖 Mini Chatbot (Facebook BlenderBot-90M)",
 
51
  examples=["Hello!", "Tell me a fun fact", "How are you today?"],
52
  )
53
 
54
+
55
  if __name__ == "__main__":
56
  demo.launch(share=True)