Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -20,9 +20,9 @@ HF_TOKEN = os.environ.get("HUGGINGFACE_API_KEY", None)
|
|
20 |
if not HF_TOKEN:
|
21 |
raise ValueError("Hugging Face API key not found in environment variables. Please set the HUGGINGFACE_API_KEY environment variable.")
|
22 |
|
23 |
-
# Load the tokenizer and model
|
24 |
-
tokenizer = AutoTokenizer.from_pretrained("meta-llama/Meta-Llama-3-8B-Instruct")
|
25 |
-
model = AutoModelForCausalLM.from_pretrained("meta-llama/Meta-Llama-3-8B-Instruct", device_map="auto")
|
26 |
|
27 |
# Function to refine and translate text using Meta-Llama 3B
|
28 |
def refine_text(prompt):
|
@@ -40,7 +40,7 @@ def get_answer(user_question, threshold=0.30):
|
|
40 |
|
41 |
# Find the most similar question
|
42 |
max_similarity = np.max(similarities)
|
43 |
-
if max_similarity > threshold:
|
44 |
# Get the index of the most similar question
|
45 |
similar_question_idx = np.argmax(similarities)
|
46 |
# Retrieve the corresponding answer
|
@@ -65,4 +65,5 @@ iface = gr.Interface(
|
|
65 |
description="Ask questions related to blood donation and get answers.",
|
66 |
)
|
67 |
|
68 |
-
|
|
|
|
20 |
if not HF_TOKEN:
|
21 |
raise ValueError("Hugging Face API key not found in environment variables. Please set the HUGGINGFACE_API_KEY environment variable.")
|
22 |
|
23 |
+
# Load the tokenizer and model with authentication
|
24 |
+
tokenizer = AutoTokenizer.from_pretrained("meta-llama/Meta-Llama-3-8B-Instruct", use_auth_token=HF_TOKEN)
|
25 |
+
model = AutoModelForCausalLM.from_pretrained("meta-llama/Meta-Llama-3-8B-Instruct", use_auth_token=HF_TOKEN, device_map="auto")
|
26 |
|
27 |
# Function to refine and translate text using Meta-Llama 3B
|
28 |
def refine_text(prompt):
|
|
|
40 |
|
41 |
# Find the most similar question
|
42 |
max_similarity = np.max(similarities)
|
43 |
+
if (max_similarity > threshold):
|
44 |
# Get the index of the most similar question
|
45 |
similar_question_idx = np.argmax(similarities)
|
46 |
# Retrieve the corresponding answer
|
|
|
65 |
description="Ask questions related to blood donation and get answers.",
|
66 |
)
|
67 |
|
68 |
+
if __name__ == "__main__":
|
69 |
+
iface.launch()
|