MojoHz commited on
Commit
5819c8e
·
verified ·
1 Parent(s): bf01e94

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -4
app.py CHANGED
@@ -1,12 +1,17 @@
 
1
  import pandas as pd
2
  import numpy as np
3
  from sklearn.feature_extraction.text import TfidfVectorizer
4
  from sklearn.metrics.pairwise import cosine_similarity
5
- from transformers import pipeline, HfApi, HfFolder
6
  import gradio as gr
7
 
8
- # Hugging Face login - Ensure that you are logged into Hugging Face before running this space
9
- HfFolder.save_token("<your_hugging_face_token>") # This is set once to avoid token exposure in the code
 
 
 
 
10
 
11
  # Load and preprocess the data
12
  def preprocess_data(file_path):
@@ -67,7 +72,7 @@ def main_pipeline(file_path, user_query):
67
  retrieved_text = "\n".join(results['Knowledge_Text'].tolist())
68
 
69
  # Use Llama3.2 for question answering with prompt engineering
70
- llm = pipeline("text-generation", model="meta-llama/Llama-3.2-1B-Instruct")
71
  prompt = (
72
  f"You are an expert sports analyst. Based on the following training data, provide a detailed and insightful answer to the user's question. "
73
  f"Always include relevant numerical data in your response. Limit your response to a maximum of 200 words.\n\n"
 
1
+ import os
2
  import pandas as pd
3
  import numpy as np
4
  from sklearn.feature_extraction.text import TfidfVectorizer
5
  from sklearn.metrics.pairwise import cosine_similarity
6
+ from transformers import pipeline
7
  import gradio as gr
8
 
9
+ # Access the Hugging Face token from the environment variable
10
+ HF_TOKEN = os.getenv("HF_Token")
11
+
12
+ # Ensure the token is loaded correctly (optional)
13
+ if not HF_TOKEN:
14
+ raise ValueError("Hugging Face token not found. Please set it as a secret.")
15
 
16
  # Load and preprocess the data
17
  def preprocess_data(file_path):
 
72
  retrieved_text = "\n".join(results['Knowledge_Text'].tolist())
73
 
74
  # Use Llama3.2 for question answering with prompt engineering
75
+ llm = pipeline("text-generation", model="meta-llama/Llama-3.2-1B-Instruct", use_auth_token=HF_TOKEN)
76
  prompt = (
77
  f"You are an expert sports analyst. Based on the following training data, provide a detailed and insightful answer to the user's question. "
78
  f"Always include relevant numerical data in your response. Limit your response to a maximum of 200 words.\n\n"