Spaces:
Runtime error
Runtime error
Up
Browse files
app.py
CHANGED
|
@@ -3,15 +3,24 @@ import random
|
|
| 3 |
from fuzzywuzzy import process
|
| 4 |
from flask import Flask, request, render_template
|
| 5 |
import joblib
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
-
|
| 10 |
-
with open(
|
| 11 |
intents = json.load(file)
|
| 12 |
|
| 13 |
-
|
| 14 |
-
nlp = joblib.load(
|
| 15 |
|
| 16 |
# Extract all possible questions for fuzzy matching
|
| 17 |
all_questions = []
|
|
@@ -36,7 +45,7 @@ def fuzzy_match(text, questions, threshold=80):
|
|
| 36 |
def chatbot_response(user_input):
|
| 37 |
intent, confidence = get_intent(user_input)
|
| 38 |
|
| 39 |
-
if confidence > 0.75: # If
|
| 40 |
for intent_data in intents["intents"]:
|
| 41 |
if intent_data["tag"] == intent:
|
| 42 |
return random.choice(intent_data["responses"])
|
|
@@ -52,6 +61,8 @@ def chatbot_response(user_input):
|
|
| 52 |
return "Sorry, I didn't understand that. Can you rephrase?"
|
| 53 |
|
| 54 |
# Flask routes
|
|
|
|
|
|
|
| 55 |
@app.route("/")
|
| 56 |
def index():
|
| 57 |
return render_template("chat.html") # Make sure chat.html exists
|
|
@@ -63,4 +74,4 @@ def chat():
|
|
| 63 |
return response
|
| 64 |
|
| 65 |
if __name__ == "__main__":
|
| 66 |
-
app.run(debug=False)
|
|
|
|
| 3 |
from fuzzywuzzy import process
|
| 4 |
from flask import Flask, request, render_template
|
| 5 |
import joblib
|
| 6 |
+
from huggingface_hub import hf_hub_download
|
| 7 |
+
import os
|
| 8 |
+
from dotenv import load_dotenv
|
| 9 |
|
| 10 |
+
def config():
|
| 11 |
+
load_dotenv()
|
| 12 |
+
|
| 13 |
+
API_Key = os.getenv('token')
|
| 14 |
+
database_ID = os.getenv('db_database_ID')
|
| 15 |
+
fl_name = os.getenv('fl_name')
|
| 16 |
+
model_name = os.getenv('model_name')
|
| 17 |
|
| 18 |
+
intents_path = hf_hub_download(repo_id=database_ID, filename=fl_name, use_auth_token=API_Key)
|
| 19 |
+
with open(intents_path, "r") as file:
|
| 20 |
intents = json.load(file)
|
| 21 |
|
| 22 |
+
model_path = hf_hub_download(repo_id=database_ID, filename=model_name, use_auth_token=API_Key)
|
| 23 |
+
nlp = joblib.load(model_path)
|
| 24 |
|
| 25 |
# Extract all possible questions for fuzzy matching
|
| 26 |
all_questions = []
|
|
|
|
| 45 |
def chatbot_response(user_input):
|
| 46 |
intent, confidence = get_intent(user_input)
|
| 47 |
|
| 48 |
+
if confidence > 0.75: # If model is confident
|
| 49 |
for intent_data in intents["intents"]:
|
| 50 |
if intent_data["tag"] == intent:
|
| 51 |
return random.choice(intent_data["responses"])
|
|
|
|
| 61 |
return "Sorry, I didn't understand that. Can you rephrase?"
|
| 62 |
|
| 63 |
# Flask routes
|
| 64 |
+
app = Flask(__name__)
|
| 65 |
+
|
| 66 |
@app.route("/")
|
| 67 |
def index():
|
| 68 |
return render_template("chat.html") # Make sure chat.html exists
|
|
|
|
| 74 |
return response
|
| 75 |
|
| 76 |
if __name__ == "__main__":
|
| 77 |
+
app.run(debug=False)
|