KiranRand commited on
Commit
70474f4
·
verified ·
1 Parent(s): a7277d9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -13,10 +13,8 @@ model.config.pad_token_id = model.config.eos_token_id
13
 
14
  # Chat function
15
  def chat_with_gpt2(user_input):
16
- # Encode input
17
  inputs = tokenizer.encode(user_input, return_tensors="pt", truncation=True, max_length=512)
18
 
19
- # Generate response (limit output for speed and memory)
20
  outputs = model.generate(
21
  inputs,
22
  max_length=250, # shortened for performance
@@ -28,14 +26,16 @@ def chat_with_gpt2(user_input):
28
  pad_token_id=tokenizer.eos_token_id
29
  )
30
 
31
- # Decode response
32
  response = tokenizer.decode(outputs[0], skip_special_tokens=True)
33
-
34
- # Return only the bot's reply (not repeating input)
35
  return response[len(user_input):].strip()
36
 
37
  # Gradio UI
38
  interface = gr.Interface(
39
  fn=chat_with_gpt2,
40
  inputs=gr.Textbox(lines=3, placeholder="Ask me about your trip..."),
41
- outputs="
 
 
 
 
 
 
13
 
14
  # Chat function
15
  def chat_with_gpt2(user_input):
 
16
  inputs = tokenizer.encode(user_input, return_tensors="pt", truncation=True, max_length=512)
17
 
 
18
  outputs = model.generate(
19
  inputs,
20
  max_length=250, # shortened for performance
 
26
  pad_token_id=tokenizer.eos_token_id
27
  )
28
 
 
29
  response = tokenizer.decode(outputs[0], skip_special_tokens=True)
 
 
30
  return response[len(user_input):].strip()
31
 
32
  # Gradio UI
33
  interface = gr.Interface(
34
  fn=chat_with_gpt2,
35
  inputs=gr.Textbox(lines=3, placeholder="Ask me about your trip..."),
36
+ outputs="text",
37
+ title="Trip Planner Chatbot",
38
+ description="Ask anything related to your travel or itinerary!"
39
+ )
40
+
41
+ interface.launch()