palbha commited on
Commit
3b06642
·
verified ·
1 Parent(s): 33e213d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -36
app.py CHANGED
@@ -1,47 +1,27 @@
1
  import streamlit as st
2
- # Import from the correct package
3
  from langchain_google_genai import ChatGoogleGenerativeAI
4
- from langchain.tools import Tool
5
- from langchain.agents import initialize_agent
6
- from langchain.agents import AgentType
7
- from langchain.tools import DuckDuckGoSearchRun
8
  from google.ai.generativelanguage_v1beta.types import Tool as GenAITool
9
- import os
10
 
11
-
12
- # Configure LangChain LLM with Gemini
13
- llm = ChatGoogleGenerativeAI(model="gemini-1.5-flash", google_api_key=os.getenv("gemini_api"))
14
-
15
- # Use DuckDuckGo Search (no API key needed)
16
- ddgs = DuckDuckGoSearchRun()
17
- search_tool = Tool(
18
- name="Web Search",
19
- func=ddgs.run,
20
- description="Searches the web for relevant certification information."
21
- )
22
-
23
- # Create LangChain agent
24
- agent = initialize_agent(
25
- tools=#[search_tool],
26
- [GenAITool(google_search={})],
27
- llm=llm,
28
- agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
29
- verbose=True
30
- )
31
 
32
  def azure_cert_bot(cert_name):
33
  query = f"Microsoft Azure {cert_name} certification curriculum site:microsoft.com"
34
- search_results = ddgs.run(query).split("\n")
35
- prompt = f"Based on the following curriculum details, generate key questions and answers in markdown format for the {cert_name} certification exam. Do not include any metadata or unnecessary text, only return the formatted Q&A:\n{search_results}"
36
- response = llm.invoke(prompt)
 
 
 
37
 
38
  try:
39
- response_text = response.get("content", "No response generated.") if isinstance(response, dict) else response
40
  response_text = "\n".join([line for line in response_text.split("\n") if not line.lower().startswith("content=") and "metadata" not in line.lower()])
41
  except Exception as e:
42
  response_text = f"Error processing response: {str(e)}"
43
 
44
- return search_results, response_text
45
 
46
  # Streamlit UI Enhancements
47
  st.set_page_config(page_title="Azure Certification Prep Assistant", layout="wide")
@@ -80,12 +60,10 @@ st.markdown("<div class='title'>Azure Certification Prep Assistant</div>", unsaf
80
  cert_name = st.text_input("Enter Azure Certification Name (e.g., AZ-900)", "")
81
  if st.button("Get Certification Details"):
82
  if cert_name:
83
- links, qa_content = azure_cert_bot(cert_name)
84
 
85
- st.markdown("<div class='subheader'>Certification Links & Curriculum</div>", unsafe_allow_html=True)
86
- for link in links:
87
- if link.strip():
88
- st.markdown(f"<div class='markdown-text-container'>- <a href='{link}' target='_blank'>{link}</a></div>", unsafe_allow_html=True)
89
 
90
  st.markdown("<div class='subheader'>Exam Questions & Answers</div>", unsafe_allow_html=True)
91
  st.markdown(f"<div class='markdown-text-container'>{qa_content}</div>", unsafe_allow_html=True)
 
1
  import streamlit as st
 
2
  from langchain_google_genai import ChatGoogleGenerativeAI
 
 
 
 
3
  from google.ai.generativelanguage_v1beta.types import Tool as GenAITool
4
+ import json
5
 
6
+ # Configure LangChain LLM with Gemini 2.0
7
+ llm = ChatGoogleGenerativeAI(model="gemini-2.0-flash", google_api_key=os.getenv("gemini_api"))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
 
9
  def azure_cert_bot(cert_name):
10
  query = f"Microsoft Azure {cert_name} certification curriculum site:microsoft.com"
11
+
12
+ # Use Gemini's built-in Google Search tool
13
+ resp = llm.invoke(
14
+ f"Find the Microsoft documentation for {cert_name} and generate key Q&A based on the curriculum.",
15
+ tools=[GenAITool(google_search={})],
16
+ )
17
 
18
  try:
19
+ response_text = resp.get("content", "No response generated.") if isinstance(resp, dict) else resp
20
  response_text = "\n".join([line for line in response_text.split("\n") if not line.lower().startswith("content=") and "metadata" not in line.lower()])
21
  except Exception as e:
22
  response_text = f"Error processing response: {str(e)}"
23
 
24
+ return query, response_text
25
 
26
  # Streamlit UI Enhancements
27
  st.set_page_config(page_title="Azure Certification Prep Assistant", layout="wide")
 
60
  cert_name = st.text_input("Enter Azure Certification Name (e.g., AZ-900)", "")
61
  if st.button("Get Certification Details"):
62
  if cert_name:
63
+ search_query, qa_content = azure_cert_bot(cert_name)
64
 
65
+ st.markdown("<div class='subheader'>Certification Search Query</div>", unsafe_allow_html=True)
66
+ st.markdown(f"<div class='markdown-text-container'>🔍 {search_query}</div>", unsafe_allow_html=True)
 
 
67
 
68
  st.markdown("<div class='subheader'>Exam Questions & Answers</div>", unsafe_allow_html=True)
69
  st.markdown(f"<div class='markdown-text-container'>{qa_content}</div>", unsafe_allow_html=True)