-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
44 lines (38 loc) · 1.99 KB
/
main.py
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
import streamlit as st
import requests
url = 'https://api.berri.ai/create_app'
data = {'user_email': '[email protected]'}
st.title('Berrylit - a Berri.ai and Streamlit Implementation')
st.write("This code provides a simple interface for users to upload a PDF file and ask a question related to it. The code utilizes Streamlit to create the web interface and the Berri API to process the uploaded file and provide the answer to the user's query.")
st.markdown('''Made By - [Akshat Punia](http://www.akshatpunia.com)''')
uf = st.file_uploader("Choose a PDF file", type="pdf")
user_input = st.text_input("Ask your query about the document you uploaded?")
if uf is not None and user_input != "":
pdf_bytes = uf.read()
files = {'data_source': ('uploaded.pdf', pdf_bytes)}
response = requests.post(url, files=files, data=data)
response.raise_for_status()
api_endpoint = response.json()['api_endpoint']
user_query = user_input
final_url = api_endpoint + "&query=" + user_query
response = requests.get(final_url)
system_response = response.json()["response"]
st.write(system_response)
st.markdown('''
### For running and using the chabot locally:
1. Clone the repository and navigate to the directory in your terminal.
```sh
git clone https://github.com/username/repo-name.git
cd repo-name
```
2. Install the required packages using pip.
```sh
pip install -r requirements.txt
```
3. Run the Python script using the following command:
```sh
streamlit run pdf_query_chatbot.py
```
4. The chatbot interface will open in your default browser. You can upload a PDF file by clicking on the "Choose a PDF file" button and ask your query related to the document.
Note: The code uses the Berri API to process the uploaded PDF file and provide the answer to the user's query. To use this code, you need to have a Berri API key. This code has been tested with Python 3.9.13 and Streamlit 1.14.0. The code is provided as-is and is free to use and modify.
''')