SelmaNajih001 commited on
Commit
93a8701
·
verified ·
1 Parent(s): 319925e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -5
app.py CHANGED
@@ -42,13 +42,27 @@ Question:
42
  {question}
43
  """
44
  prompt = PromptTemplate(template=prompt_template, input_variables=["context", "question"])
 
45
 
46
- # Carica FAISS dal dataset
47
- faiss_index_path = hf_hub_download(repo_id="SelmaNajih001/DatasetStockFAISS", filename="index.faiss")
48
- docstore_path = hf_hub_download(repo_id="SelmaNajih001/DatasetStockFAISS", filename="docstore.json")
49
 
50
- embeddings = HuggingFaceEmbeddings(model_name="sentence-transformers/multi-qa-mpnet-base-dot-v1")
51
- vectorstore = FAISS.load_local("faiss_index", embeddings)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
  def analisi_finanziaria(query, k=4):
53
  # Recupera i documenti più rilevanti
54
  docs_found = vectorstore.similarity_search(query, k=k)
 
42
  {question}
43
  """
44
  prompt = PromptTemplate(template=prompt_template, input_variables=["context", "question"])
45
+ embeddings = HuggingFaceEmbeddings(model_name="sentence-transformers/multi-qa-mpnet-base-dot-v1")
46
 
 
 
 
47
 
48
+ import tempfile
49
+ tmp_dir = tempfile.mkdtemp()
50
+
51
+ # Scarica i file nella cartella temporanea
52
+ faiss_index_path = hf_hub_download(
53
+ repo_id="SelmaNajih001/DatasetStockFAISS",
54
+ filename="index.faiss",
55
+ cache_dir=tmp_dir
56
+ )
57
+ docstore_path = hf_hub_download(
58
+ repo_id="SelmaNajih001/DatasetStockFAISS",
59
+ filename="index.pkl",
60
+ cache_dir=tmp_dir
61
+ )
62
+
63
+ # Usa la cartella per caricare FAISS
64
+ vectorstore = FAISS.load_local(tmp_dir, embeddings)
65
+
66
  def analisi_finanziaria(query, k=4):
67
  # Recupera i documenti più rilevanti
68
  docs_found = vectorstore.similarity_search(query, k=k)