zineb36 commited on
Commit
5467e23
·
verified ·
1 Parent(s): 5ee6a91

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -5
app.py CHANGED
@@ -1,4 +1,4 @@
1
- # CodeAlpha Task 2: Chatbot for FAQs - Final Fixed Version
2
  from sklearn.feature_extraction.text import TfidfVectorizer
3
  from sklearn.metrics.pairwise import cosine_similarity
4
  import numpy as np
@@ -23,7 +23,7 @@ answers = list(faqs.values())
23
  vectorizer = TfidfVectorizer(stop_words='english')
24
  tfidf_matrix = vectorizer.fit_transform(questions)
25
 
26
- # Step 3: Chat function - Fixed format
27
  def chatbot_response(message, history):
28
  if not message.strip():
29
  return "", history
@@ -38,7 +38,9 @@ def chatbot_response(message, history):
38
  else:
39
  bot_msg = "🤔 I don't have specific info on that. Try: 'What is CodeAlpha?' or 'What is TF-IDF?'"
40
 
41
- history.append((message, bot_msg))
 
 
42
  return "", history
43
 
44
  # Step 4: Premium CSS
@@ -109,7 +111,7 @@ custom_css = """
109
  }
110
  """
111
 
112
- # Step 5: Create App
113
  with gr.Blocks(css=custom_css, theme=gr.themes.Base()) as demo:
114
  gr.HTML("""
115
  <div id="header">
@@ -123,6 +125,7 @@ with gr.Blocks(css=custom_css, theme=gr.themes.Base()) as demo:
123
  height=500,
124
  label="AI Assistant",
125
  show_label=False,
 
126
  avatar_images=("https://i.imgur.com/8Km9tLL.png", "https://i.imgur.com/2oBz7ag.png")
127
  )
128
 
@@ -141,7 +144,6 @@ with gr.Blocks(css=custom_css, theme=gr.themes.Base()) as demo:
141
  inputs=msg
142
  )
143
 
144
- # Fixed: return textbox first, then chatbot
145
  send.click(chatbot_response, [msg, chatbot], [msg, chatbot])
146
  msg.submit(chatbot_response, [msg, chatbot], [msg, chatbot])
147
 
 
1
+ # CodeAlpha Task 2: Chatbot for FAQs - Gradio 6.14.0 Compatible
2
  from sklearn.feature_extraction.text import TfidfVectorizer
3
  from sklearn.metrics.pairwise import cosine_similarity
4
  import numpy as np
 
23
  vectorizer = TfidfVectorizer(stop_words='english')
24
  tfidf_matrix = vectorizer.fit_transform(questions)
25
 
26
+ # Step 3: Chat function - New Gradio 6 format
27
  def chatbot_response(message, history):
28
  if not message.strip():
29
  return "", history
 
38
  else:
39
  bot_msg = "🤔 I don't have specific info on that. Try: 'What is CodeAlpha?' or 'What is TF-IDF?'"
40
 
41
+ # New format: list of dicts with role + content
42
+ history.append({"role": "user", "content": message})
43
+ history.append({"role": "assistant", "content": bot_msg})
44
  return "", history
45
 
46
  # Step 4: Premium CSS
 
111
  }
112
  """
113
 
114
+ # Step 5: Create App - type='messages' is key
115
  with gr.Blocks(css=custom_css, theme=gr.themes.Base()) as demo:
116
  gr.HTML("""
117
  <div id="header">
 
125
  height=500,
126
  label="AI Assistant",
127
  show_label=False,
128
+ type="messages", # هذا هو السر!
129
  avatar_images=("https://i.imgur.com/8Km9tLL.png", "https://i.imgur.com/2oBz7ag.png")
130
  )
131
 
 
144
  inputs=msg
145
  )
146
 
 
147
  send.click(chatbot_response, [msg, chatbot], [msg, chatbot])
148
  msg.submit(chatbot_response, [msg, chatbot], [msg, chatbot])
149