Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
|
|
| 1 |
from sklearn.feature_extraction.text import TfidfVectorizer
|
| 2 |
from sklearn.metrics.pairwise import cosine_similarity
|
| 3 |
import numpy as np
|
| 4 |
import gradio as gr
|
| 5 |
|
| 6 |
-
# Step 1: Collect FAQs
|
| 7 |
faqs = {
|
| 8 |
"What is CodeAlpha?": "CodeAlpha is a tech platform offering free virtual internships in AI, Web Development, and Data Science to help students gain practical experience.",
|
| 9 |
"How long is CodeAlpha internship?": "CodeAlpha internships last 1 month. You must complete minimum 2 out of 4 tasks to receive the completion certificate and Letter of Recommendation.",
|
|
@@ -18,7 +19,7 @@ faqs = {
|
|
| 18 |
questions = list(faqs.keys())
|
| 19 |
answers = list(faqs.values())
|
| 20 |
|
| 21 |
-
# Step 2: Preprocess using TF-IDF
|
| 22 |
vectorizer = TfidfVectorizer(stop_words='english')
|
| 23 |
tfidf_matrix = vectorizer.fit_transform(questions)
|
| 24 |
|
|
@@ -38,13 +39,15 @@ def chatbot_response(message, history):
|
|
| 38 |
else:
|
| 39 |
return "🤖 I don't have info on that. Try asking about CodeAlpha internship, TF-IDF, or cosine similarity."
|
| 40 |
|
| 41 |
-
# Step 5: Create
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
description="Ask me about CodeAlpha internship or NLP concepts! Uses TF-IDF + Cosine Similarity",
|
| 46 |
-
examples=["What is CodeAlpha?", "When is submission deadline?", "What is TF-IDF?"],
|
| 47 |
-
theme=gr.themes.Soft()
|
| 48 |
-
)
|
| 49 |
|
| 50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# CodeAlpha Task 2: Chatbot for FAQs
|
| 2 |
from sklearn.feature_extraction.text import TfidfVectorizer
|
| 3 |
from sklearn.metrics.pairwise import cosine_similarity
|
| 4 |
import numpy as np
|
| 5 |
import gradio as gr
|
| 6 |
|
| 7 |
+
# Step 1: Collect FAQs
|
| 8 |
faqs = {
|
| 9 |
"What is CodeAlpha?": "CodeAlpha is a tech platform offering free virtual internships in AI, Web Development, and Data Science to help students gain practical experience.",
|
| 10 |
"How long is CodeAlpha internship?": "CodeAlpha internships last 1 month. You must complete minimum 2 out of 4 tasks to receive the completion certificate and Letter of Recommendation.",
|
|
|
|
| 19 |
questions = list(faqs.keys())
|
| 20 |
answers = list(faqs.values())
|
| 21 |
|
| 22 |
+
# Step 2: Preprocess using TF-IDF
|
| 23 |
vectorizer = TfidfVectorizer(stop_words='english')
|
| 24 |
tfidf_matrix = vectorizer.fit_transform(questions)
|
| 25 |
|
|
|
|
| 39 |
else:
|
| 40 |
return "🤖 I don't have info on that. Try asking about CodeAlpha internship, TF-IDF, or cosine similarity."
|
| 41 |
|
| 42 |
+
# Step 5: Create Chat UI - الصيغة الصحيحة
|
| 43 |
+
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 44 |
+
gr.Markdown("# CodeAlpha FAQ Chatbot - Task 2")
|
| 45 |
+
gr.Markdown("Ask me about CodeAlpha internship or NLP concepts! Uses TF-IDF + Cosine Similarity")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
+
gr.ChatInterface(
|
| 48 |
+
fn=chatbot_response,
|
| 49 |
+
examples=["What is CodeAlpha?", "When is submission deadline?", "What is TF-IDF?"],
|
| 50 |
+
chatbot=gr.Chatbot(height=400),
|
| 51 |
+
)
|
| 52 |
+
|
| 53 |
+
demo.launch()
|