Spaces:
Sleeping
Sleeping
Suraj Yadav
commited on
Commit
β’
b7da83e
1
Parent(s):
59ec4f3
Created a github action workflow
Browse files- .github/workflows/main.yaml +25 -0
- app.py +51 -0
- requirements.txt +32 -0
.github/workflows/main.yaml
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: Sync to Hugging Face hub
|
2 |
+
on:
|
3 |
+
push:
|
4 |
+
branches: [main]
|
5 |
+
|
6 |
+
# to run this workflow manually from the Actions tab
|
7 |
+
workflow_dispatch:
|
8 |
+
|
9 |
+
jobs:
|
10 |
+
sync-to-hub:
|
11 |
+
runs-on: ubuntu-latest
|
12 |
+
steps:
|
13 |
+
- uses: actions/checkout@v3
|
14 |
+
with:
|
15 |
+
fetch-depth: 0
|
16 |
+
lfs: false
|
17 |
+
|
18 |
+
- name: Push to hub
|
19 |
+
env:
|
20 |
+
HF_TOKEN: ${{ secrets.HF_TOKEN }}
|
21 |
+
run: git push --force https://Suraj-Yadav:$HF_TOKEN@huggingface.co/spaces/Suraj-Yadav/Search_Engine_LLM main
|
22 |
+
|
23 |
+
# git push https://HF_USERNAME:$HF_TOKEN@huggingface.co/spaces/HF_USERNAME/SPACE_NAME main
|
24 |
+
|
25 |
+
|
app.py
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from langchain_groq import ChatGroq
|
3 |
+
from langchain_community.utilities import ArxivAPIWrapper,WikipediaAPIWrapper
|
4 |
+
from langchain_community.tools import ArxivQueryRun,WikipediaQueryRun,DuckDuckGoSearchRun
|
5 |
+
from langchain.agents import initialize_agent,AgentType
|
6 |
+
from langchain.callbacks import StreamlitCallbackHandler
|
7 |
+
import os
|
8 |
+
from dotenv import load_dotenv
|
9 |
+
|
10 |
+
## Arxiv and wikipedia Tools
|
11 |
+
arxiv_wrapper=ArxivAPIWrapper(top_k_results=1, doc_content_chars_max=200)
|
12 |
+
arxiv=ArxivQueryRun(api_wrapper=arxiv_wrapper)
|
13 |
+
|
14 |
+
api_wrapper=WikipediaAPIWrapper(top_k_results=1,doc_content_chars_max=200)
|
15 |
+
wiki=WikipediaQueryRun(api_wrapper=api_wrapper)
|
16 |
+
|
17 |
+
search=DuckDuckGoSearchRun(name="Search")
|
18 |
+
|
19 |
+
|
20 |
+
st.title("π LangChain - Chat with search")
|
21 |
+
"""
|
22 |
+
In this example, we're using `StreamlitCallbackHandler` to display the thoughts and actions of an agent in an interactive Streamlit app.
|
23 |
+
Try more LangChain π€ Streamlit Agent examples at [github.com/langchain-ai/streamlit-agent](https://github.com/langchain-ai/streamlit-agent).
|
24 |
+
"""
|
25 |
+
|
26 |
+
## Sidebar for settings
|
27 |
+
st.sidebar.title("Settings")
|
28 |
+
api_key=st.sidebar.text_input("Enter your Groq API Key:",type="password")
|
29 |
+
|
30 |
+
if "messages" not in st.session_state:
|
31 |
+
st.session_state['messages'] = [
|
32 |
+
{"role":"assisstant","content":"Hi,I'm a chatbot who can search the web. How can I help you?"}
|
33 |
+
]
|
34 |
+
|
35 |
+
for msg in st.session_state.messages:
|
36 |
+
st.chat_message(msg["role"]).write(msg['content'])
|
37 |
+
|
38 |
+
if prompt:=st.chat_input(placeholder="What is machine learning?"):
|
39 |
+
st.session_state.messages.append({"role":"user","content":prompt})
|
40 |
+
st.chat_message("user").write(prompt)
|
41 |
+
|
42 |
+
llm=ChatGroq(groq_api_key=api_key,model_name="Llama3-8b-8192",streaming=True)
|
43 |
+
tools=[search,arxiv,wiki]
|
44 |
+
|
45 |
+
search_agent=initialize_agent(tools,llm,agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,handling_parsing_errors=False)
|
46 |
+
|
47 |
+
with st.chat_message("assistant"):
|
48 |
+
st_cb=StreamlitCallbackHandler(st.container(),expand_new_thoughts=False)
|
49 |
+
response=search_agent.run(st.session_state.messages,callbacks=[st_cb])
|
50 |
+
st.session_state.messages.append({'role':'assistant',"content":response})
|
51 |
+
st.write(response)
|
requirements.txt
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
langchain
|
2 |
+
python-dotenv
|
3 |
+
ipykernel
|
4 |
+
langchain-community
|
5 |
+
pypdf
|
6 |
+
bs4
|
7 |
+
arxiv
|
8 |
+
pymupdf
|
9 |
+
wikipedia
|
10 |
+
langchain-text-splitters
|
11 |
+
langchain-openai
|
12 |
+
chromadb
|
13 |
+
sentence_transformers
|
14 |
+
langchain_huggingface
|
15 |
+
faiss-cpu
|
16 |
+
langchain_chroma
|
17 |
+
duckdb
|
18 |
+
pandas
|
19 |
+
openai
|
20 |
+
langchain-groq
|
21 |
+
duckduckgo_search==5.3.1b1
|
22 |
+
pymupdf
|
23 |
+
arxiv
|
24 |
+
wikipedia
|
25 |
+
mysql-connector-python
|
26 |
+
SQLAlchemy
|
27 |
+
validators==0.28.1
|
28 |
+
youtube_transcript_api
|
29 |
+
unstructured
|
30 |
+
pytube
|
31 |
+
numexpr
|
32 |
+
huggingface_hub
|