Spaces:
Sleeping
Sleeping
judebebo32
commited on
Commit
•
fd2040c
1
Parent(s):
d906e7d
Update app.py
Browse files
app.py
CHANGED
@@ -4,19 +4,14 @@ from nltk.stem import PorterStemmer
|
|
4 |
from nltk.tokenize import word_tokenize
|
5 |
from sklearn.feature_extraction.text import TfidfVectorizer
|
6 |
from sklearn.metrics.pairwise import cosine_similarity
|
7 |
-
|
8 |
-
import os
|
9 |
-
|
10 |
-
# Initialize the Flask app
|
11 |
-
app = Flask(__name__)
|
12 |
|
13 |
# Download necessary NLTK data
|
14 |
nltk.download('punkt')
|
15 |
nltk.download('stopwords')
|
16 |
|
17 |
# Load customer inquiries dataset
|
18 |
-
|
19 |
-
with open(file_path, 'r') as f:
|
20 |
data = f.readlines()
|
21 |
|
22 |
# Preprocess data
|
@@ -34,26 +29,21 @@ tfidf_matrix = vectorizer.fit_transform(data)
|
|
34 |
|
35 |
# Define chatbot logic
|
36 |
def chatbot_response(user_input):
|
37 |
-
preprocessed_input = preprocess_text(user_input)
|
38 |
input_vector = vectorizer.transform([user_input])
|
39 |
cosine_similarities = cosine_similarity(input_vector, tfidf_matrix)
|
40 |
most_similar_index = cosine_similarities.argmax()
|
41 |
return data[most_similar_index].strip()
|
42 |
|
43 |
-
#
|
44 |
-
|
45 |
-
|
46 |
-
return
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
# Main entry
|
58 |
-
if __name__ == '__main__':
|
59 |
-
app.run(host='0.0.0.0', port=8080)
|
|
|
4 |
from nltk.tokenize import word_tokenize
|
5 |
from sklearn.feature_extraction.text import TfidfVectorizer
|
6 |
from sklearn.metrics.pairwise import cosine_similarity
|
7 |
+
import gradio as gr
|
|
|
|
|
|
|
|
|
8 |
|
9 |
# Download necessary NLTK data
|
10 |
nltk.download('punkt')
|
11 |
nltk.download('stopwords')
|
12 |
|
13 |
# Load customer inquiries dataset
|
14 |
+
with open('my_text_file.txt', 'r') as f:
|
|
|
15 |
data = f.readlines()
|
16 |
|
17 |
# Preprocess data
|
|
|
29 |
|
30 |
# Define chatbot logic
|
31 |
def chatbot_response(user_input):
|
|
|
32 |
input_vector = vectorizer.transform([user_input])
|
33 |
cosine_similarities = cosine_similarity(input_vector, tfidf_matrix)
|
34 |
most_similar_index = cosine_similarities.argmax()
|
35 |
return data[most_similar_index].strip()
|
36 |
|
37 |
+
# Create Gradio interface
|
38 |
+
def chatbot_interface(user_input):
|
39 |
+
response = chatbot_response(user_input)
|
40 |
+
return response
|
41 |
+
|
42 |
+
iface = gr.Interface(fn=chatbot_interface,
|
43 |
+
inputs="text",
|
44 |
+
outputs="text",
|
45 |
+
title="FAQ Chatbot",
|
46 |
+
description="Enter a question to get a response from the chatbot based on the preloaded FAQ data.")
|
47 |
+
|
48 |
+
if __name__ == "__main__":
|
49 |
+
iface.launch()
|
|
|
|
|
|
|
|