Ariyal/random-psycho
0
1import pandas as pd2import streamlit as st3from crewai import Crew, Task, Agent4from langchain_community.tools import DuckDuckGoSearchRun5from langchain_google_genai import ChatGoogleGenerativeAI6import os7 8# Initialize LLM and tools9llm = ChatGoogleGenerativeAI(10 google_api_key=os.getenv("GOOGLE_API_KEY"),11 model="gemini-pro",12 temperature=0.7,13 top_p=0.8514)15search = DuckDuckGoSearchRun()16 17def researcher_agent():18 return Agent(19 llm=llm,20 role="Senior Researcher",21 goal="Find the past research and publication activity of the research scholar.",22 backstory="You are a veteran researcher who tracks research activity of all the scholars.",23 allow_delegation=False,24 tools=[search],25 verbose=1,26 )27 28def researcher_task(SCHOLAR_NAME):29 research_agent = researcher_agent()30 return Task(31 description=f"""Crawl different popular academic databases like Google Scholar, DBLP, etc and list out publications done by the scholar mentioned.32 SCHOLAR = {SCHOLAR_NAME}33 """,34 expected_output="A detailed bullet point on each of the publications. Each bullet point should cover the title, co-authors, journal/conference and abstract of the paper.",35 agent=research_agent,36 )37 38def summarizer_agent():39 return Agent(40 llm=llm,41 role="Senior Publication Summarizer",42 goal="Write brief summary on each research publication of the scholar using the provided research in a paragraph.",43 backstory="You are a veteran research publications summarizer who summarizes the research concisely without losing important information.",44 allow_delegation=False,45 verbose=1,46 )47 48def summarizer_task(scholar_name):49 summarize_agent = summarizer_agent()50 return Task(51 description=f"""Write an engaging summary on research activity of the scholar mentioned.52 SCHOLAR = {scholar_name}53 """,54 expected_output="Paragraphs containing concise summary for each publication of the scholar",55 agent=summarize_agent,56 )57 58# def index():59# return render_template('index.html')60 61def process_excel(file):62 summaries = []63 if file:64 faculties = pd.read_excel(file)65 researcher = researcher_agent() # Create agent once66 summarizer = summarizer_agent() # Create agent once67 68 for i in range(len(faculties["SCHOLAR_NAME"])):69 SCHOLAR_NAME = faculties["SCHOLAR_NAME"][i]70 with st.spinner(f"Generating Summary for {SCHOLAR_NAME}"):71 research_task = researcher_task(SCHOLAR_NAME)72 summarize_task = summarizer_task(SCHOLAR_NAME)73 74 crew = Crew(agents=[researcher, summarizer], tasks=[research_task, summarize_task], verbose=1)75 result = crew.kickoff()76 77 summaries.append(f"--- Results for Scholar {SCHOLAR_NAME} ---\n")78 summaries.append(f"{result}\n\n")79 80 st.html("<hr>")81 st.html(f"<center><h2>Results for Scholar {SCHOLAR_NAME}</h2></center>")82 st.markdown(f"{result}")83 st.write(f"\n\n")84 85 return summaries86 87 88st.title("Multi-Agent RAG System")89 90# Step 1: Upload Excel file91uploaded_file = st.file_uploader("Upload an Excel file", type=["xlsx"])92 93if uploaded_file is not None:94 # Step 2: Display the uploaded Excel file95 st.write("Uploaded Excel File:")96 df = pd.read_excel(uploaded_file)97 st.write(df)98 99 # Step 3: Process the file and display results100 if st.button("Generate Summaries"):101 result = process_excel(uploaded_file)102 103 # Display the result104 # st.write("Generated Summaries:")105 # for summary in result:106 # st.text(summary)107 108 