Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,22 +1,25 @@
|
|
1 |
import json
|
2 |
import os
|
3 |
from flask import Flask, request, jsonify
|
4 |
-
from transformers import pipeline
|
5 |
-
|
6 |
-
|
7 |
from transformers import pipeline
|
8 |
from huggingface_hub import login
|
9 |
|
10 |
-
#
|
11 |
-
|
12 |
-
|
13 |
-
# Load the model
|
14 |
-
llm = pipeline("text-generation", model="tiiuae/falcon-1b-instruct")
|
15 |
|
|
|
|
|
16 |
|
|
|
|
|
17 |
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
-
# Load the schemes data from JSON
|
20 |
SCHEMES_FILE = "schemes.json"
|
21 |
|
22 |
if os.path.exists(SCHEMES_FILE):
|
@@ -32,7 +35,7 @@ def find_scheme_info(query):
|
|
32 |
for scheme in schemes_data.get("schemes", []):
|
33 |
if query.lower() in scheme["name"].lower() or query.lower() in scheme["description"].lower():
|
34 |
return scheme["description"]
|
35 |
-
return None
|
36 |
|
37 |
# Function to generate chatbot response
|
38 |
def chatbot_response(query):
|
|
|
1 |
import json
|
2 |
import os
|
3 |
from flask import Flask, request, jsonify
|
|
|
|
|
|
|
4 |
from transformers import pipeline
|
5 |
from huggingface_hub import login
|
6 |
|
7 |
+
# Retrieve Hugging Face token securely
|
8 |
+
hf_token = os.getenv("chatbot")
|
|
|
|
|
|
|
9 |
|
10 |
+
if hf_token is None:
|
11 |
+
raise ValueError("Hugging Face token is missing! Set HF_TOKEN in your environment variables or Secrets.")
|
12 |
|
13 |
+
# Log in with Hugging Face token
|
14 |
+
login(token=hf_token)
|
15 |
|
16 |
+
# Load the model (Falcon-1B)
|
17 |
+
try:
|
18 |
+
llm = pipeline("text-generation", model="tiiuae/falcon-1b-instruct", token=hf_token)
|
19 |
+
except Exception as e:
|
20 |
+
raise RuntimeError(f"Error loading model: {str(e)}")
|
21 |
|
22 |
+
# Load the schemes data from JSON file
|
23 |
SCHEMES_FILE = "schemes.json"
|
24 |
|
25 |
if os.path.exists(SCHEMES_FILE):
|
|
|
35 |
for scheme in schemes_data.get("schemes", []):
|
36 |
if query.lower() in scheme["name"].lower() or query.lower() in scheme["description"].lower():
|
37 |
return scheme["description"]
|
38 |
+
return None
|
39 |
|
40 |
# Function to generate chatbot response
|
41 |
def chatbot_response(query):
|