Spaces:
Paused
Paused
test
Browse files
app.py
CHANGED
@@ -3,89 +3,91 @@ import requests
|
|
3 |
from PyPDF2 import PdfReader
|
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 |
-
|
45 |
-
|
46 |
-
|
|
|
|
|
47 |
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
def get_response_from_fastapi(prompt):
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
# μ΄κΈ° νμ΄μ§ μ€μ
|
80 |
-
if "page" not in st.session_state:
|
81 |
-
|
82 |
-
|
83 |
-
# paper_name μ΄κΈ°ν
|
84 |
-
if "paper_name" not in st.session_state:
|
85 |
-
|
86 |
-
|
87 |
-
# νμ΄μ§ λ λλ§
|
88 |
-
if st.session_state.page == "main":
|
89 |
-
|
90 |
-
elif st.session_state.page == "chat":
|
91 |
-
|
|
|
3 |
from PyPDF2 import PdfReader
|
4 |
|
5 |
|
6 |
+
st.title("Welcome to GemmaPaperQA")
|
7 |
+
st.subheader("Upload Your Paper")
|
8 |
+
|
9 |
+
# def main_page():
|
10 |
+
|
11 |
+
|
12 |
+
# paper = st.file_uploader("Upload Here!", type="pdf", label_visibility="hidden")
|
13 |
+
# if paper:
|
14 |
+
# st.write(f"Upload complete! File name is {paper.name}")
|
15 |
+
# st.write("Please click the button below.")
|
16 |
+
# # pdf_reader = PdfReader(paper)
|
17 |
+
# # for page in pdf_reader.pages:
|
18 |
+
# # paper_title.append(page.extract_text())
|
19 |
+
# # break
|
20 |
+
# # paper_name = paper_title[0].split("\n")[0]
|
21 |
+
|
22 |
+
# # st.subheader(f"You upload the <{paper_name}> paper")
|
23 |
+
|
24 |
+
# if st.button("Click Here :)"):
|
25 |
+
# # FastAPI μλ²μ PDF νμΌ μ μ‘
|
26 |
+
# try:
|
27 |
+
# files = {"file": (paper.name, paper, "application/pdf")}
|
28 |
+
# response = requests.post(f"{FASTAPI_URL}/upload_pdf", files=files)
|
29 |
+
# if response.status_code == 200:
|
30 |
+
# st.success("PDF successfully uploaded to the model! Please click the button again")
|
31 |
+
# st.session_state.messages = []
|
32 |
+
# st.session_state.paper_name = paper.name[:-4]
|
33 |
+
# st.session_state.page = "chat"
|
34 |
+
# else:
|
35 |
+
# st.error(f"Failed to upload PDF to the model. Error: {response.text}")
|
36 |
+
# except requests.RequestException as e:
|
37 |
+
# st.error(f"Error connecting to the server: {str(e)}")
|
38 |
+
|
39 |
+
# def chat_page():
|
40 |
+
# st.title(f"Welcome to GemmaPaperQA")
|
41 |
+
# st.subheader(f"Ask anything about {st.session_state.paper_name}")
|
42 |
+
|
43 |
+
# if "messages" not in st.session_state:
|
44 |
+
# st.session_state.messages = []
|
45 |
+
|
46 |
+
# for message in st.session_state.messages:
|
47 |
+
# with st.chat_message(message["role"]):
|
48 |
+
# st.markdown(message["content"])
|
49 |
|
50 |
+
# if prompt := st.chat_input("Chat here !"):
|
51 |
+
# # Add user message to chat history
|
52 |
+
# st.session_state.messages.append({"role": "user", "content": prompt})
|
53 |
+
|
54 |
+
# # Display user message in chat message container
|
55 |
+
# with st.chat_message("user"):
|
56 |
+
# st.markdown(prompt)
|
57 |
+
|
58 |
+
# # Get response from FastAPI server
|
59 |
+
# response = get_response_from_fastapi(prompt)
|
60 |
+
|
61 |
+
# # Display assistant response in chat message container
|
62 |
+
# with st.chat_message("assistant"):
|
63 |
+
# st.markdown(response)
|
64 |
+
|
65 |
+
# # Add assistant response to chat history
|
66 |
+
# st.session_state.messages.append({"role": "assistant", "content": response})
|
67 |
+
|
68 |
+
# if st.button("Go back to main page"):
|
69 |
+
# st.session_state.page = "main"
|
70 |
+
|
71 |
+
# def get_response_from_fastapi(prompt):
|
72 |
+
# try:
|
73 |
+
# response = requests.post(f"{FASTAPI_URL}/ask", json={"text": prompt})
|
74 |
+
# if response.status_code == 200:
|
75 |
+
# return response.json()["response"]
|
76 |
+
# else:
|
77 |
+
# return f"Sorry, I couldn't generate a response. Error: {response.text}"
|
78 |
+
# except requests.RequestException as e:
|
79 |
+
# return f"Sorry, there was an error connecting to the server: {str(e)}"
|
80 |
+
|
81 |
+
# # μ΄κΈ° νμ΄μ§ μ€μ
|
82 |
+
# if "page" not in st.session_state:
|
83 |
+
# st.session_state.page = "main"
|
84 |
+
|
85 |
+
# # paper_name μ΄κΈ°ν
|
86 |
+
# if "paper_name" not in st.session_state:
|
87 |
+
# st.session_state.paper_name = ""
|
88 |
+
|
89 |
+
# # νμ΄μ§ λ λλ§
|
90 |
+
# if st.session_state.page == "main":
|
91 |
+
# main_page()
|
92 |
+
# elif st.session_state.page == "chat":
|
93 |
+
# chat_page()
|