zineb36 commited on
Commit
29e30e7
·
verified ·
1 Parent(s): 5467e23

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -7
app.py CHANGED
@@ -1,4 +1,4 @@
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,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 - New Gradio 6 format
27
  def chatbot_response(message, history):
28
  if not message.strip():
29
  return "", history
@@ -38,7 +38,7 @@ 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
- # 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
@@ -111,8 +111,8 @@ custom_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">
118
  <h1>💬 CodeAlpha AI Assistant</h1>
@@ -121,11 +121,11 @@ with gr.Blocks(css=custom_css, theme=gr.themes.Base()) as demo:
121
  </div>
122
  """)
123
 
 
124
  chatbot = gr.Chatbot(
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
 
@@ -154,4 +154,5 @@ with gr.Blocks(css=custom_css, theme=gr.themes.Base()) as demo:
154
  </div>
155
  """)
156
 
157
- demo.launch()
 
 
1
+ # CodeAlpha Task 2: FAQ Chatbot - Gradio 6.14.0 Fixed
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 - 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
+ # Gradio 6 format: list of dicts
42
  history.append({"role": "user", "content": message})
43
  history.append({"role": "assistant", "content": bot_msg})
44
  return "", history
 
111
  }
112
  """
113
 
114
+ # Step 5: Create App - NO theme/css here!
115
+ with gr.Blocks() as demo:
116
  gr.HTML("""
117
  <div id="header">
118
  <h1>💬 CodeAlpha AI Assistant</h1>
 
121
  </div>
122
  """)
123
 
124
+ # Removed type parameter - Gradio 6 detects it automatically
125
  chatbot = gr.Chatbot(
126
  height=500,
127
  label="AI Assistant",
128
  show_label=False,
 
129
  avatar_images=("https://i.imgur.com/8Km9tLL.png", "https://i.imgur.com/2oBz7ag.png")
130
  )
131
 
 
154
  </div>
155
  """)
156
 
157
+ # Moved theme and css to launch() - Gradio 6 requirement
158
+ demo.launch(css=custom_css, theme=gr.themes.Base())