Update front_end.py
Browse files- front_end.py +32 -67
front_end.py
CHANGED
|
@@ -1,67 +1,32 @@
|
|
| 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 |
-
import streamlit as st
|
| 36 |
-
import requests
|
| 37 |
-
|
| 38 |
-
st.set_page_config(page_title="ChatPDF", page_icon="π")
|
| 39 |
-
|
| 40 |
-
st.title("π ChatPDF")
|
| 41 |
-
uploaded_file = st.file_uploader("Upload a PDF file", type="pdf")
|
| 42 |
-
|
| 43 |
-
if 'pdf_processed' not in st.session_state:
|
| 44 |
-
st.session_state['pdf_processed'] = False
|
| 45 |
-
|
| 46 |
-
if uploaded_file is not None and not st.session_state['pdf_processed']:
|
| 47 |
-
upload_file = {'file': uploaded_file}
|
| 48 |
-
response = requests.post(url='http://127.0.0.1:8000/upload_pdf', files=upload_file)
|
| 49 |
-
if response.status_code == 200:
|
| 50 |
-
st.session_state['pdf_processed'] = True
|
| 51 |
-
st.write("PDF processed and vectors upserted!")
|
| 52 |
-
else:
|
| 53 |
-
st.write("Failed to process PDF")
|
| 54 |
-
|
| 55 |
-
if st.session_state['pdf_processed']:
|
| 56 |
-
st.title("π€ Ask a Question about the PDF Content")
|
| 57 |
-
add_selectbox = st.sidebar.selectbox("Select Model", ("Default", "deepset/roberta-base-squad2", "llama"))
|
| 58 |
-
question = st.text_input("Ask a question about the PDF content:")
|
| 59 |
-
if question:
|
| 60 |
-
url = f"http://127.0.0.1:8000/ask_question/?question={question}&model={add_selectbox}"
|
| 61 |
-
response = requests.post(url)
|
| 62 |
-
if response.status_code == 200:
|
| 63 |
-
st.write(response.json()['answer'])
|
| 64 |
-
else:
|
| 65 |
-
st.write("Failed to get an answer")
|
| 66 |
-
|
| 67 |
-
## streamlit run C:\Yash\Streamlit\front_end.py
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import requests
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
st.set_page_config(page_title="ChatPDF", page_icon="π")
|
| 6 |
+
|
| 7 |
+
st.title("π ChatPDF")
|
| 8 |
+
uploaded_file = st.file_uploader("Upload a PDF file", type="pdf")
|
| 9 |
+
|
| 10 |
+
if 'pdf_processed' not in st.session_state:
|
| 11 |
+
st.session_state['pdf_processed'] = False
|
| 12 |
+
|
| 13 |
+
if uploaded_file is not None and not st.session_state['pdf_processed']:
|
| 14 |
+
upload_file = {'file': uploaded_file}
|
| 15 |
+
response = requests.post(url='http://127.0.0.1:8000/upload_pdf', files=upload_file)
|
| 16 |
+
if response.status_code == 200:
|
| 17 |
+
st.session_state['pdf_processed'] = True
|
| 18 |
+
st.write("PDF processed and vectors upserted!")
|
| 19 |
+
else:
|
| 20 |
+
st.write("Failed to process PDF")
|
| 21 |
+
|
| 22 |
+
if st.session_state['pdf_processed']:
|
| 23 |
+
st.title("π€ Ask a Question about the PDF Content")
|
| 24 |
+
add_selectbox = st.sidebar.selectbox("Select Model", ("Default", "deepset/roberta-base-squad2", "llama"))
|
| 25 |
+
question = st.text_input("Ask a question about the PDF content:")
|
| 26 |
+
if question:
|
| 27 |
+
url = f"http://127.0.0.1:8000/ask_question/?question={question}&model={add_selectbox}"
|
| 28 |
+
response = requests.post(url)
|
| 29 |
+
if response.status_code == 200:
|
| 30 |
+
st.write(response.json()['answer'])
|
| 31 |
+
else:
|
| 32 |
+
st.write("Failed to get an answer")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|