kashyaparun commited on
Commit
8f2067c
·
verified ·
1 Parent(s): e39248e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -39
app.py CHANGED
@@ -69,22 +69,13 @@ st.write("---")
69
  # Sidebar for API key configuration
70
  with st.sidebar:
71
  st.title("⚙️ Configuration")
72
- api_key_source = st.radio("Select API Key Provider:",
73
- ["Google (Gemini)", "OpenAI"],
74
- help="Choose which AI provider to use")
75
 
76
- if api_key_source == "Google (Gemini)":
77
- api_key = st.text_input("Enter your Gemini API Key", type="password",
78
- help="Required for the AI model to function")
79
- if api_key:
80
- os.environ["GEMINI_API_KEY"] = api_key
81
- os.environ["GOOGLE_API_KEY"] = api_key
82
- else:
83
- api_key = st.text_input("Enter your OpenAI API Key", type="password",
84
- help="Required for the AI model to function")
85
- if api_key:
86
- os.environ["OPENAI_API_KEY"] = api_key
87
-
88
  st.divider()
89
 
90
  # Reset button
@@ -93,7 +84,6 @@ with st.sidebar:
93
  del st.session_state[key]
94
  st.rerun()
95
 
96
-
97
  #---------------------------- Utility Functions ----------------------------#
98
 
99
  def extract_text_from_pdf(file):
@@ -398,6 +388,7 @@ class CaseBreakdownCrew:
398
  self.api_key = api_key
399
 
400
  def create_metadata_agent(self):
 
401
  return Agent(
402
  role="Metadata Analyzer",
403
  goal="Extract title and author information from document content",
@@ -409,6 +400,7 @@ class CaseBreakdownCrew:
409
  )
410
 
411
  def create_content_generator_agent(self):
 
412
  return Agent(
413
  role="Case Study Content Generator",
414
  goal="Generate comprehensive case analysis content based on section requirements",
@@ -420,6 +412,7 @@ class CaseBreakdownCrew:
420
  )
421
 
422
  def create_content_reviewer_agent(self):
 
423
  return Agent(
424
  role="Content Quality Reviewer",
425
  goal="Evaluate and score content for quality, relevance, and depth",
@@ -607,16 +600,10 @@ def create_teaching_plan_crew(file_paths, llm_provider="gemini"):
607
  tracker.set_placeholder(st.empty())
608
 
609
  # Initialize LLM based on provider
610
- if llm_provider == "gemini":
611
- my_llm = LLM(
612
- model='gemini/gemini-2.0-flash',
613
- api_key=os.environ.get("GEMINI_API_KEY")
614
- )
615
- else:
616
  my_llm = LLM(
617
- model='gpt-4-turbo',
618
- api_key=os.environ.get("OPENAI_API_KEY")
619
- )
620
 
621
  # Define agents with callbacks for UI updates
622
  pdf_analyzer = Agent(
@@ -708,21 +695,15 @@ def create_teaching_plan_crew(file_paths, llm_provider="gemini"):
708
  #---------------------------- Board Plan Generator ----------------------------#
709
 
710
  class BoardPlanAnalyzer:
711
- def __init__(self, llm_provider="gemini"):
712
- if llm_provider == "gemini":
713
- api_key = os.environ.get('GEMINI_API_KEY')
714
- self.model = "gemini/gemini-2.0-flash"
715
- else:
716
- api_key = os.environ.get('OPENAI_API_KEY')
717
- self.model = "gpt-4-turbo"
718
 
719
  if not api_key:
720
- raise ValueError(f"{llm_provider.capitalize()} API key not found")
721
 
722
- if llm_provider == "gemini":
723
- os.environ['GEMINI_API_KEY'] = api_key
724
- else:
725
- os.environ['OPENAI_API_KEY'] = api_key
726
 
727
  litellm.set_verbose = True
728
 
@@ -745,6 +726,7 @@ class BoardPlanAnalyzer:
745
  description="Extracts text content from PDF files"
746
  )],
747
  allow_delegation=False,
 
748
  verbose=True
749
  )
750
 
@@ -761,6 +743,7 @@ class BoardPlanAnalyzer:
761
  description="Analyzes case study and creates structured board plan"
762
  )],
763
  allow_delegation=False,
 
764
  verbose=True
765
  )
766
 
@@ -904,7 +887,7 @@ if st.session_state.uploaded_files:
904
  st.warning("⚠️ Please enter an API key in the sidebar before proceeding.")
905
  else:
906
  # Initialize the breakdown generator
907
- crew_manager = CaseBreakdownCrew(api_key)
908
 
909
  # Extract metadata
910
  with st.spinner("Extracting document metadata..."):
@@ -1098,7 +1081,7 @@ if st.session_state.uploaded_files:
1098
  progress_bar = progress_placeholder.progress(0)
1099
 
1100
  # Select LLM provider
1101
- llm_provider = "gemini" if api_key_source == "Google (Gemini)" else "openai"
1102
 
1103
  # Update progress
1104
  progress_bar.progress(10)
 
69
  # Sidebar for API key configuration
70
  with st.sidebar:
71
  st.title("⚙️ Configuration")
 
 
 
72
 
73
+ api_key = st.text_input("Enter your Gemini API Key", type="password",
74
+ help="Required for the AI model to function")
75
+ if api_key:
76
+ os.environ["GEMINI_API_KEY"] = api_key
77
+ os.environ["GOOGLE_API_KEY"] = api_key
78
+
 
 
 
 
 
 
79
  st.divider()
80
 
81
  # Reset button
 
84
  del st.session_state[key]
85
  st.rerun()
86
 
 
87
  #---------------------------- Utility Functions ----------------------------#
88
 
89
  def extract_text_from_pdf(file):
 
388
  self.api_key = api_key
389
 
390
  def create_metadata_agent(self):
391
+ llm = LLM(model='gemini/gemini-2.0-flash', api_key=self.api_key)
392
  return Agent(
393
  role="Metadata Analyzer",
394
  goal="Extract title and author information from document content",
 
400
  )
401
 
402
  def create_content_generator_agent(self):
403
+ llm = LLM(model='gemini/gemini-2.0-flash', api_key=self.api_key)
404
  return Agent(
405
  role="Case Study Content Generator",
406
  goal="Generate comprehensive case analysis content based on section requirements",
 
412
  )
413
 
414
  def create_content_reviewer_agent(self):
415
+ llm = LLM(model='gemini/gemini-2.0-flash', api_key=self.api_key)
416
  return Agent(
417
  role="Content Quality Reviewer",
418
  goal="Evaluate and score content for quality, relevance, and depth",
 
600
  tracker.set_placeholder(st.empty())
601
 
602
  # Initialize LLM based on provider
 
 
 
 
 
 
603
  my_llm = LLM(
604
+ model='gemini/gemini-2.0-flash',
605
+ api_key=os.environ.get("GEMINI_API_KEY")
606
+ )
607
 
608
  # Define agents with callbacks for UI updates
609
  pdf_analyzer = Agent(
 
695
  #---------------------------- Board Plan Generator ----------------------------#
696
 
697
  class BoardPlanAnalyzer:
698
+ def __init__(self):
699
+ api_key = os.environ.get('GEMINI_API_KEY')
700
+ self.model = "gemini/gemini-2.0-flash"
 
 
 
 
701
 
702
  if not api_key:
703
+ raise ValueError("Gemini API key not found")
704
 
705
+ os.environ['GEMINI_API_KEY'] = api_key
706
+ self.api_key = api_key
 
 
707
 
708
  litellm.set_verbose = True
709
 
 
726
  description="Extracts text content from PDF files"
727
  )],
728
  allow_delegation=False,
729
+ llm=self.model,
730
  verbose=True
731
  )
732
 
 
743
  description="Analyzes case study and creates structured board plan"
744
  )],
745
  allow_delegation=False,
746
+ llm=self.model,
747
  verbose=True
748
  )
749
 
 
887
  st.warning("⚠️ Please enter an API key in the sidebar before proceeding.")
888
  else:
889
  # Initialize the breakdown generator
890
+ crew_manager = CaseBreakdownCrew(api_key, api_key_source)
891
 
892
  # Extract metadata
893
  with st.spinner("Extracting document metadata..."):
 
1081
  progress_bar = progress_placeholder.progress(0)
1082
 
1083
  # Select LLM provider
1084
+ llm_provider = "gemini"
1085
 
1086
  # Update progress
1087
  progress_bar.progress(10)