Spaces:
Runtime error
Runtime error
File size: 2,851 Bytes
7f909a0 ea1e36e 7f909a0 3b06642 ea1e36e 7f909a0 3b06642 7f909a0 ea1e36e 3b06642 7f909a0 3b06642 7f909a0 ea1e36e 5c7d00e 7f909a0 5c7d00e 7f909a0 ea1e36e 5c7d00e ea1e36e a41e24b ea1e36e 7f909a0 ea1e36e 7f909a0 ea1e36e a41e24b ea1e36e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
import streamlit as st
from langchain_google_genai import ChatGoogleGenerativeAI
from langchain.tools import Tool
from langchain_community.tools.google_search import GoogleSearchResults
import json
# Get API key for Gemini
GEMINI_API_KEY = userdata.get("gemini_api")
# Configure LangChain LLM with Gemini 2.0
llm = ChatGoogleGenerativeAI(model="gemini-2.0-flash-exp", google_api_key=os.getenv("gemini_api"))
# Google Search Tool (does not require API key)
google_search = GoogleSearchResults()
search_tool = Tool(
name="Google Search",
func=google_search.run,
description="Search the web for information.",
)
def azure_cert_bot(cert_name):
query = f"Microsoft Azure {cert_name} certification curriculum site:microsoft.com"
# Perform Google Search
search_results = search_tool.run(query)
# Generate Q&A using Gemini
prompt = (
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}"
)
response = llm.invoke(prompt)
try:
response_text = response.get("content", "No response generated.") if isinstance(response, dict) else response
except Exception as e:
response_text = f"Error processing response: {str(e)}"
return search_results, response_text
# Streamlit UI Enhancements
st.set_page_config(page_title="Azure Certification Prep Assistant", layout="wide")
# Custom Styling
st.markdown("""
<style>
body {
font-family: 'Arial', sans-serif;
}
.stApp {
background-color: #f5f7fa;
}
.title {
text-align: center;
color: #1f77b4;
font-size: 36px;
font-weight: bold;
}
.subheader {
color: #ff5733;
font-size: 24px;
font-weight: bold;
}
.markdown-text-container {
background-color: white;
padding: 15px;
border-radius: 10px;
box-shadow: 2px 2px 10px rgba(0,0,0,0.1);
}
</style>
""", unsafe_allow_html=True)
st.markdown("<div class='title'>Azure Certification Prep Assistant</div>", unsafe_allow_html=True)
cert_name = st.text_input("Enter Azure Certification Name (e.g., AZ-900)", "")
if st.button("Get Certification Details"):
if cert_name:
links, qa_content = azure_cert_bot(cert_name)
st.markdown("<div class='subheader'>Certification Links & Curriculum</div>", unsafe_allow_html=True)
st.markdown(f"<div class='markdown-text-container'>{links}</div>", unsafe_allow_html=True)
st.markdown("<div class='subheader'>Exam Questions & Answers</div>", unsafe_allow_html=True)
st.markdown(f"<div class='markdown-text-container'>{qa_content}</div>", unsafe_allow_html=True)
else:
st.warning("Please enter a certification name.")
|