Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,27 +1,42 @@
|
|
|
|
1 |
import streamlit as st
|
2 |
from langchain_google_genai import ChatGoogleGenerativeAI
|
3 |
-
from
|
|
|
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 |
-
#
|
13 |
-
|
14 |
-
|
15 |
-
|
|
|
|
|
16 |
)
|
|
|
17 |
|
18 |
try:
|
19 |
-
response_text =
|
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
|
25 |
|
26 |
# Streamlit UI Enhancements
|
27 |
st.set_page_config(page_title="Azure Certification Prep Assistant", layout="wide")
|
@@ -60,10 +75,10 @@ st.markdown("<div class='title'>Azure Certification Prep Assistant</div>", unsaf
|
|
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 |
-
|
64 |
|
65 |
-
st.markdown("<div class='subheader'>Certification
|
66 |
-
st.markdown(f"<div class='markdown-text-container'
|
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)
|
|
|
1 |
+
|
2 |
import streamlit as st
|
3 |
from langchain_google_genai import ChatGoogleGenerativeAI
|
4 |
+
from langchain.tools import Tool
|
5 |
+
from langchain_community.tools.google_search import GoogleSearchResults
|
6 |
import json
|
7 |
|
8 |
+
# Get API key for Gemini
|
9 |
+
GEMINI_API_KEY = userdata.get("gemini_api")
|
10 |
+
|
11 |
# Configure LangChain LLM with Gemini 2.0
|
12 |
+
llm = ChatGoogleGenerativeAI(model="gemini-2.0-flash-exp", google_api_key=os.getenv("gemini_api"))
|
13 |
+
|
14 |
+
# Google Search Tool (does not require API key)
|
15 |
+
google_search = GoogleSearchResults()
|
16 |
+
search_tool = Tool(
|
17 |
+
name="Google Search",
|
18 |
+
func=google_search.run,
|
19 |
+
description="Search the web for information.",
|
20 |
+
)
|
21 |
|
22 |
def azure_cert_bot(cert_name):
|
23 |
query = f"Microsoft Azure {cert_name} certification curriculum site:microsoft.com"
|
24 |
|
25 |
+
# Perform Google Search
|
26 |
+
search_results = search_tool.run(query)
|
27 |
+
|
28 |
+
# Generate Q&A using Gemini
|
29 |
+
prompt = (
|
30 |
+
f"Based on the following curriculum details, generate key questions and answers in markdown format for the {cert_name} certification exam:\n\n{search_results}"
|
31 |
)
|
32 |
+
response = llm.invoke(prompt)
|
33 |
|
34 |
try:
|
35 |
+
response_text = response.get("content", "No response generated.") if isinstance(response, dict) else response
|
|
|
36 |
except Exception as e:
|
37 |
response_text = f"Error processing response: {str(e)}"
|
38 |
|
39 |
+
return search_results, response_text
|
40 |
|
41 |
# Streamlit UI Enhancements
|
42 |
st.set_page_config(page_title="Azure Certification Prep Assistant", layout="wide")
|
|
|
75 |
cert_name = st.text_input("Enter Azure Certification Name (e.g., AZ-900)", "")
|
76 |
if st.button("Get Certification Details"):
|
77 |
if cert_name:
|
78 |
+
links, qa_content = azure_cert_bot(cert_name)
|
79 |
|
80 |
+
st.markdown("<div class='subheader'>Certification Links & Curriculum</div>", unsafe_allow_html=True)
|
81 |
+
st.markdown(f"<div class='markdown-text-container'>{links}</div>", unsafe_allow_html=True)
|
82 |
|
83 |
st.markdown("<div class='subheader'>Exam Questions & Answers</div>", unsafe_allow_html=True)
|
84 |
st.markdown(f"<div class='markdown-text-container'>{qa_content}</div>", unsafe_allow_html=True)
|