Update app.py
Browse files254 unmodified lines25525625725825926012 unmodified lines273274275276277278279280281282283284132 unmodified lines417418419420421422423424425426427428429430431432433434435436254 unmodified linesreturn summarydef rank_search_results(titles, summaries, model):ranking_prompt = ("Rank the following search results from a financial analyst perspective. "f"Assign a rank from 1 to {len(titles)} based on relevance, with 1 being the most relevant. "12 unmodified lines# Check if we have the correct number of ranksif len(ranks) != len(titles):raise ValueError("Number of ranks does not match number of titles")return ranksexcept Exception as e:print(f"Error in ranking: {str(e)}. Using fallback ranking method.")# Fallback: assign ranks based on original orderreturn list(range(1, len(titles) + 1))def ask_question(question, temperature, top_p, repetition_penalty, web_search):132 unmodified linescurrent_date = datetime.now().strftime("%Y-%m-%d")for result, summary, rank in zip(search_results, summaries, ranks):doc = Document(page_content=summary,metadata={"search_date": current_date,"search_title": result["title"],"search_content": result["text"],"search_summary": summary,"rank": rank})database.add_documents([doc])database.save_local("faiss_database")def export_vector_db_to_excel():embed = get_embeddings()254 unmodified lines25525625725825926026126226326412 unmodified lines277278279280281282283284285286287288289132 unmodified lines422423424425426427428429430431432433434435436437438439440441442443444445446447254 unmodified linesreturn summarydef rank_search_results(titles, summaries, model):if not titles or not summaries:print("No titles or summaries to rank.")return list(range(1, len(titles) + 1))ranking_prompt = ("Rank the following search results from a financial analyst perspective. "f"Assign a rank from 1 to {len(titles)} based on relevance, with 1 being the most relevant. "12 unmodified lines# Check if we have the correct number of ranksif len(ranks) != len(titles):print(f"Warning: Number of ranks ({len(ranks)}) does not match number of titles ({len(titles)})")print(f"Model output: {ranks_str}")return list(range(1, len(titles) + 1))return ranksexcept Exception as e:print(f"Error in ranking: {str(e)}. Using fallback ranking method.")return list(range(1, len(titles) + 1))def ask_question(question, temperature, top_p, repetition_penalty, web_search):132 unmodified linescurrent_date = datetime.now().strftime("%Y-%m-%d")documents = []for result, summary, rank in zip(search_results, summaries, ranks):if summary: # Only create a document if there's a summarydoc = Document(page_content=summary,metadata={"search_date": current_date,"search_title": result["title"],"search_content": result["text"],"search_summary": summary,"rank": rank})documents.append(doc)if documents: # Only update the database if there are documents to adddatabase.add_documents(documents)database.save_local("faiss_database")else:print("No valid documents to add to the database.")def export_vector_db_to_excel():embed = get_embeddings()
app.py+25-14