Aluode commited on
Commit
f76e339
·
verified ·
1 Parent(s): 0c8ec8c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -3
app.py CHANGED
@@ -53,9 +53,19 @@ def generate_text(prompt, max_new_tokens=80, temperature=0.7):
53
  def chat_interface(message, history):
54
  """Formats the Gradio UI input to match your dataset's User/Bot structure."""
55
  prompt = ""
56
- # Inject context memory
57
- for user_msg, bot_msg in history:
58
- prompt += f"User: {user_msg}\nBot: {bot_msg}\n"
 
 
 
 
 
 
 
 
 
 
59
 
60
  # Inject current message
61
  prompt += f"User: {message}\nBot:"
 
53
  def chat_interface(message, history):
54
  """Formats the Gradio UI input to match your dataset's User/Bot structure."""
55
  prompt = ""
56
+
57
+ # Inject context memory (Handles both Gradio 4 and Gradio 5 formats)
58
+ for msg in history:
59
+ # Gradio 5 format: dictionaries with 'role' and 'content'
60
+ if isinstance(msg, dict):
61
+ if msg.get("role") == "user":
62
+ prompt += f"User: {msg.get('content')}\n"
63
+ elif msg.get("role") == "assistant":
64
+ prompt += f"Bot: {msg.get('content')}\n"
65
+
66
+ # Fallback for Gradio 4 format: [user_msg, bot_msg]
67
+ elif isinstance(msg, (list, tuple)) and len(msg) == 2:
68
+ prompt += f"User: {msg[0]}\nBot: {msg[1]}\n"
69
 
70
  # Inject current message
71
  prompt += f"User: {message}\nBot:"