Update app.py
Browse files
app.py
CHANGED
|
@@ -1,23 +1,23 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
from langchain.agents import AgentType, initialize_agent
|
| 3 |
from langchain import HuggingFaceHub
|
| 4 |
-
from langchain.tools import Tool
|
| 5 |
-
import os
|
| 6 |
from datetime import datetime
|
| 7 |
from langchain.tools import DuckDuckGoSearchRun
|
|
|
|
| 8 |
|
| 9 |
-
|
| 10 |
token = os.environ['HF_TOKEN']
|
| 11 |
-
|
| 12 |
hub_llm = HuggingFaceHub(
|
| 13 |
-
|
| 14 |
-
huggingfacehub_api_token=token
|
|
|
|
| 15 |
|
| 16 |
# Set the page title and icon
|
| 17 |
st.set_page_config(
|
| 18 |
page_title="AI Driven Search",
|
| 19 |
page_icon="🔍",
|
| 20 |
-
layout="wide",
|
| 21 |
)
|
| 22 |
|
| 23 |
# Custom CSS style for the title block
|
|
@@ -41,7 +41,7 @@ st.markdown(
|
|
| 41 |
|
| 42 |
# Title block with custom styling
|
| 43 |
st.markdown('<div class="title-block">', unsafe_allow_html=True)
|
| 44 |
-
st.title("🌐 AI
|
| 45 |
st.markdown("### Find what you're looking for with the power of AI!")
|
| 46 |
st.markdown("</div>", unsafe_allow_html=True)
|
| 47 |
|
|
@@ -49,56 +49,44 @@ st.markdown("</div>", unsafe_allow_html=True)
|
|
| 49 |
st.markdown('<div class="subtitle">', unsafe_allow_html=True)
|
| 50 |
st.subheader("How it works:")
|
| 51 |
st.write(
|
| 52 |
-
"Our search engine is powered by
|
| 53 |
-
"that understand your queries and provide accurate results.
|
| 54 |
)
|
| 55 |
st.markdown("</div>", unsafe_allow_html=True)
|
| 56 |
|
| 57 |
-
#
|
| 58 |
-
|
| 59 |
-
# Example search input
|
| 60 |
-
# search_query = st.text_input("Enter your search query:")
|
| 61 |
with st.form(key="form"):
|
| 62 |
user_input = st.text_input("Ask your question")
|
| 63 |
-
submit_clicked = st.form_submit_button("
|
| 64 |
|
| 65 |
-
|
| 66 |
-
# Example search button
|
| 67 |
-
# if st.button("Search", key="search_button"):
|
| 68 |
if submit_clicked:
|
| 69 |
-
|
| 70 |
-
# Add your AI-powered search functionality here
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
# Define a new tool that returns the current datetime
|
| 74 |
datetime_tool = Tool(
|
| 75 |
name="Datetime",
|
| 76 |
func=lambda x: datetime.now().isoformat(),
|
| 77 |
-
description="Returns the current datetime"
|
| 78 |
)
|
| 79 |
search = DuckDuckGoSearchRun()
|
| 80 |
search_tool = Tool(
|
| 81 |
-
name="
|
| 82 |
func=search,
|
| 83 |
-
description="
|
| 84 |
)
|
| 85 |
|
| 86 |
-
|
| 87 |
-
|
| 88 |
agent_chain = initialize_agent(
|
| 89 |
[search_tool, datetime_tool],
|
| 90 |
hub_llm,
|
| 91 |
agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
|
| 92 |
verbose=True,
|
| 93 |
-
handle_parsing_errors
|
| 94 |
)
|
| 95 |
result = agent_chain.run(user_input)
|
| 96 |
st.success(result)
|
| 97 |
|
| 98 |
-
# Add any other components or features as needed
|
| 99 |
-
|
| 100 |
# Footer with custom styling
|
| 101 |
st.markdown(
|
| 102 |
-
'<p style="text-align:center; color:#7f8c8d;">Built with ❤️ by Abhishek |
|
|
|
|
| 103 |
unsafe_allow_html=True,
|
| 104 |
)
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
from langchain.agents import AgentType, initialize_agent
|
| 3 |
from langchain import HuggingFaceHub
|
| 4 |
+
from langchain.tools import Tool
|
|
|
|
| 5 |
from datetime import datetime
|
| 6 |
from langchain.tools import DuckDuckGoSearchRun
|
| 7 |
+
import os
|
| 8 |
|
| 9 |
+
# Set up Hugging Face Hub
|
| 10 |
token = os.environ['HF_TOKEN']
|
|
|
|
| 11 |
hub_llm = HuggingFaceHub(
|
| 12 |
+
repo_id='mistralai/Mixtral-8x7B-Instruct-v0.1',
|
| 13 |
+
huggingfacehub_api_token=token
|
| 14 |
+
)
|
| 15 |
|
| 16 |
# Set the page title and icon
|
| 17 |
st.set_page_config(
|
| 18 |
page_title="AI Driven Search",
|
| 19 |
page_icon="🔍",
|
| 20 |
+
layout="wide",
|
| 21 |
)
|
| 22 |
|
| 23 |
# Custom CSS style for the title block
|
|
|
|
| 41 |
|
| 42 |
# Title block with custom styling
|
| 43 |
st.markdown('<div class="title-block">', unsafe_allow_html=True)
|
| 44 |
+
st.title("🌐 AI Powered Search Engine")
|
| 45 |
st.markdown("### Find what you're looking for with the power of AI!")
|
| 46 |
st.markdown("</div>", unsafe_allow_html=True)
|
| 47 |
|
|
|
|
| 49 |
st.markdown('<div class="subtitle">', unsafe_allow_html=True)
|
| 50 |
st.subheader("How it works:")
|
| 51 |
st.write(
|
| 52 |
+
"Our search engine is powered by DuckDuckGo search and uses language models "
|
| 53 |
+
"that understand your queries and provide accurate results."
|
| 54 |
)
|
| 55 |
st.markdown("</div>", unsafe_allow_html=True)
|
| 56 |
|
| 57 |
+
# Form for user input
|
|
|
|
|
|
|
|
|
|
| 58 |
with st.form(key="form"):
|
| 59 |
user_input = st.text_input("Ask your question")
|
| 60 |
+
submit_clicked = st.form_submit_button("Search")
|
| 61 |
|
| 62 |
+
# Run search if form is submitted
|
|
|
|
|
|
|
| 63 |
if submit_clicked:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
datetime_tool = Tool(
|
| 65 |
name="Datetime",
|
| 66 |
func=lambda x: datetime.now().isoformat(),
|
| 67 |
+
description="Returns the current datetime"
|
| 68 |
)
|
| 69 |
search = DuckDuckGoSearchRun()
|
| 70 |
search_tool = Tool(
|
| 71 |
+
name="Search",
|
| 72 |
func=search,
|
| 73 |
+
description="Performs an internet search using DuckDuckGo"
|
| 74 |
)
|
| 75 |
|
| 76 |
+
# Initialize the agent
|
|
|
|
| 77 |
agent_chain = initialize_agent(
|
| 78 |
[search_tool, datetime_tool],
|
| 79 |
hub_llm,
|
| 80 |
agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
|
| 81 |
verbose=True,
|
| 82 |
+
handle_parsing_errors=True,
|
| 83 |
)
|
| 84 |
result = agent_chain.run(user_input)
|
| 85 |
st.success(result)
|
| 86 |
|
|
|
|
|
|
|
| 87 |
# Footer with custom styling
|
| 88 |
st.markdown(
|
| 89 |
+
'<p style="text-align:center; color:#7f8c8d;">Built with ❤️ by Abhishek | '
|
| 90 |
+
'<a href="https://github.com/your_username/your_repo" style="color:#3498db;">GitHub Repo</a></p>',
|
| 91 |
unsafe_allow_html=True,
|
| 92 |
)
|