Spaces:
Runtime error
Runtime error
import streamlit as st | |
# Import from the correct package | |
from langchain_google_genai import ChatGoogleGenerativeAI | |
from langchain.tools import Tool | |
from langchain.agents import initialize_agent | |
from langchain.agents import AgentType | |
from langchain.tools import DuckDuckGoSearchRun | |
import os | |
# Configure LangChain LLM with Gemini | |
llm = ChatGoogleGenerativeAI(model="gemini-1.5-flash", google_api_key=os.getenv("gemini_api")) | |
# Use DuckDuckGo Search (no API key needed) | |
ddgs = DuckDuckGoSearchRun() | |
search_tool = Tool( | |
name="Web Search", | |
func=ddgs.run, | |
description="Searches the web for relevant certification information." | |
) | |
# Create LangChain agent | |
agent = initialize_agent( | |
tools=[search_tool], | |
llm=llm, | |
agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, | |
verbose=True | |
) | |
def azure_cert_bot(cert_name): | |
query = f"Microsoft Azure {cert_name} certification curriculum site:microsoft.com" | |
search_results = ddgs.run(query).split("\n") | |
prompt = f"Based on the following curriculum details, generate key questions and answers for the {cert_name} certification exam:\n{search_results}" | |
response = llm.invoke(prompt) | |
return search_results, response | |
# Streamlit UI | |
st.set_page_config(page_title="Azure Certification Prep Assistant", layout="wide") | |
st.title("Azure Certification Prep Assistant") | |
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.subheader("Certification Links & Curriculum") | |
for link in links: | |
st.markdown(f"- [{link}]({link})") | |
st.subheader("Exam Questions & Answers") | |
st.write(qa_content) | |
else: | |
st.warning("Please enter a certification name.") | |