Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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.colab import userdata # Securely storing API keys
|
9 |
+
|
10 |
+
|
11 |
+
# Configure LangChain LLM with Gemini
|
12 |
+
llm = ChatGoogleGenerativeAI(model="gemini-1.5-flash", google_api_key=GEMINI_API_KEY)
|
13 |
+
|
14 |
+
# Use DuckDuckGo Search (no API key needed)
|
15 |
+
ddgs = DuckDuckGoSearchRun()
|
16 |
+
search_tool = Tool(
|
17 |
+
name="Web Search",
|
18 |
+
func=ddgs.run,
|
19 |
+
description="Searches the web for relevant certification information."
|
20 |
+
)
|
21 |
+
|
22 |
+
# Create LangChain agent
|
23 |
+
agent = initialize_agent(
|
24 |
+
tools=[search_tool],
|
25 |
+
llm=llm,
|
26 |
+
agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
|
27 |
+
verbose=True
|
28 |
+
)
|
29 |
+
|
30 |
+
def azure_cert_bot(cert_name):
|
31 |
+
query = f"Microsoft Azure {cert_name} certification curriculum site:microsoft.com"
|
32 |
+
search_results = ddgs.run(query).split("\n")
|
33 |
+
prompt = f"Based on the following curriculum details, generate key questions and answers for the {cert_name} certification exam:\n{search_results}"
|
34 |
+
response = llm.invoke(prompt)
|
35 |
+
|
36 |
+
return search_results, response
|
37 |
+
|
38 |
+
# Streamlit UI
|
39 |
+
st.set_page_config(page_title="Azure Certification Prep Assistant", layout="wide")
|
40 |
+
st.title("Azure Certification Prep Assistant")
|
41 |
+
|
42 |
+
cert_name = st.text_input("Enter Azure Certification Name (e.g., AZ-900)", "")
|
43 |
+
if st.button("Get Certification Details"):
|
44 |
+
if cert_name:
|
45 |
+
links, qa_content = azure_cert_bot(cert_name)
|
46 |
+
|
47 |
+
st.subheader("Certification Links & Curriculum")
|
48 |
+
for link in links:
|
49 |
+
st.markdown(f"- [{link}]({link})")
|
50 |
+
|
51 |
+
st.subheader("Exam Questions & Answers")
|
52 |
+
st.write(qa_content)
|
53 |
+
else:
|
54 |
+
st.warning("Please enter a certification name.")
|