Vaishvik1618 commited on
Commit
df997fe
·
verified ·
1 Parent(s): eaa6fad

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +62 -0
  2. requirements.txt +168 -0
app.py ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import fitz # PyMuPDF
3
+ import google.generativeai as genai
4
+
5
+ # Configure the Generative AI model
6
+ genai.configure(api_key="AIzaSyBqPmsZAJrCsXme9wJBx9o4K71M9c1qzy8")
7
+
8
+ def ai_output(input_text, pdf_text, prompt):
9
+ model = genai.GenerativeModel('gemini-1.5-flash')
10
+ combined_input = f"{input_text}\n\n{pdf_text}\n\n{prompt}"
11
+ response = model.generate_content(combined_input)
12
+ return response.text
13
+
14
+ def ai_ans(input_text, prompt):
15
+ model = genai.GenerativeModel('gemini-1.5-flash')
16
+ combined_input = f"{input_text}\n\n{prompt}"
17
+ response = model.generate_content(combined_input)
18
+ return response.text
19
+
20
+ def input_pdf_setup(uploaded_file):
21
+ if uploaded_file is not None:
22
+ pdf_document = fitz.open(stream=uploaded_file.read(), filetype="pdf")
23
+ text = ""
24
+ for page_num in range(len(pdf_document)):
25
+ page = pdf_document.load_page(page_num)
26
+ text += page.get_text()
27
+ pdf_document.close()
28
+ return text
29
+ else:
30
+ raise FileNotFoundError("No file uploaded")
31
+
32
+ st.set_page_config(page_title="PDF Can Answer")
33
+ st.header("PDFchats")
34
+
35
+
36
+ uploaded_file = st.file_uploader("Upload your Document...", type=["pdf"])
37
+ input_text = st.text_area("Tell me! What is your question:", key="input")
38
+
39
+ if uploaded_file is not None:
40
+ pdf_text = input_pdf_setup(uploaded_file)
41
+ st.write("PDF file uploaded and processed successfully.")
42
+ else:
43
+ pdf_text = ""
44
+ st.write("Please upload the PDF.")
45
+
46
+ submit1 = st.button("Answer my question")
47
+
48
+
49
+ input_prompt1 = """
50
+ Act as an intelligent PDF reader. When a PDF document is uploaded, read and comprehend its content. Respond accurately to any questions asked, using the information found solely within the provided PDF and your data too get it in detaild explanation and also do web search too
51
+ """
52
+
53
+
54
+ if submit1:
55
+ if pdf_text:
56
+ response = ai_output(input_text, pdf_text, input_prompt1)
57
+ st.subheader("The Response is:")
58
+ st.write(response)
59
+ else:
60
+ st.write("Please upload the pdf.")
61
+
62
+
requirements.txt ADDED
@@ -0,0 +1,168 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ aiofiles==23.2.1
2
+ aiohappyeyeballs==2.4.3
3
+ aiohttp==3.10.10
4
+ aiosignal==1.3.1
5
+ altair==5.4.1
6
+ annotated-types==0.7.0
7
+ anyio==4.6.2.post1
8
+ asttokens==2.4.1
9
+ attrs==24.2.0
10
+ beautifulsoup4==4.12.3
11
+ blinker==1.9.0
12
+ cachetools==5.5.0
13
+ certifi==2024.8.30
14
+ charset-normalizer==3.4.0
15
+ click==8.1.7
16
+ colorama==0.4.6
17
+ comm==0.2.2
18
+ dataclasses-json==0.6.7
19
+ debugpy==1.8.7
20
+ decorator==5.1.1
21
+ Deprecated==1.2.14
22
+ dirtyjson==1.0.8
23
+ distro==1.9.0
24
+ executing==2.1.0
25
+ fastapi==0.115.5
26
+ ffmpy==0.4.0
27
+ filelock==3.16.1
28
+ frozenlist==1.5.0
29
+ fsspec==2024.10.0
30
+ gitdb==4.0.11
31
+ GitPython==3.1.43
32
+ google-ai-generativelanguage==0.6.10
33
+ google-api-core==2.23.0
34
+ google-api-python-client==2.153.0
35
+ google-auth==2.36.0
36
+ google-auth-httplib2==0.2.0
37
+ google-generativeai==0.8.3
38
+ googleapis-common-protos==1.66.0
39
+ gradio==5.6.0
40
+ gradio_client==1.4.3
41
+ greenlet==3.1.1
42
+ grpcio==1.68.0
43
+ grpcio-status==1.68.0
44
+ h11==0.14.0
45
+ httpcore==1.0.6
46
+ httplib2==0.22.0
47
+ httpx==0.27.2
48
+ huggingface-hub==0.26.2
49
+ idna==3.10
50
+ ipykernel==6.29.5
51
+ ipython==8.29.0
52
+ jedi==0.19.1
53
+ Jinja2==3.1.4
54
+ jiter==0.7.0
55
+ joblib==1.4.2
56
+ jsonschema==4.23.0
57
+ jsonschema-specifications==2024.10.1
58
+ jupyter_client==8.6.3
59
+ jupyter_core==5.7.2
60
+ llama-cloud==0.1.4
61
+ llama-index==0.11.22
62
+ llama-index-agent-openai==0.3.4
63
+ llama-index-cli==0.3.1
64
+ llama-index-core==0.11.22
65
+ llama-index-embeddings-openai==0.2.5
66
+ llama-index-indices-managed-llama-cloud==0.4.0
67
+ llama-index-legacy==0.9.48.post3
68
+ llama-index-llms-openai==0.2.16
69
+ llama-index-multi-modal-llms-openai==0.2.3
70
+ llama-index-program-openai==0.2.0
71
+ llama-index-question-gen-openai==0.2.0
72
+ llama-index-readers-file==0.2.2
73
+ llama-index-readers-llama-parse==0.3.0
74
+ llama-parse==0.5.13
75
+ lxml==5.3.0
76
+ markdown-it-py==3.0.0
77
+ MarkupSafe==2.1.5
78
+ marshmallow==3.23.1
79
+ matplotlib-inline==0.1.7
80
+ mdurl==0.1.2
81
+ mpmath==1.3.0
82
+ multidict==6.1.0
83
+ mypy-extensions==1.0.0
84
+ narwhals==1.13.5
85
+ nest-asyncio==1.6.0
86
+ networkx==3.4.2
87
+ nltk==3.9.1
88
+ numpy==1.26.4
89
+ openai==1.54.2
90
+ orjson==3.10.11
91
+ packaging==24.1
92
+ pandas==2.2.3
93
+ parso==0.8.4
94
+ pdf2image==1.17.0
95
+ pillow==11.0.0
96
+ platformdirs==4.3.6
97
+ prompt_toolkit==3.0.48
98
+ propcache==0.2.0
99
+ proto-plus==1.25.0
100
+ protobuf==5.28.3
101
+ psutil==6.1.0
102
+ pure_eval==0.2.3
103
+ pyarrow==18.0.0
104
+ pyasn1==0.6.1
105
+ pyasn1_modules==0.4.1
106
+ pydantic==2.9.2
107
+ pydantic_core==2.23.4
108
+ pydeck==0.9.1
109
+ pydub==0.25.1
110
+ Pygments==2.18.0
111
+ PyMuPDF==1.24.13
112
+ pyparsing==3.2.0
113
+ pypdf==4.3.1
114
+ PyPDF2==3.0.1
115
+ python-dateutil==2.9.0.post0
116
+ python-docx==1.1.2
117
+ python-dotenv==1.0.1
118
+ python-multipart==0.0.12
119
+ pytz==2024.2
120
+ PyYAML==6.0.2
121
+ pyzmq==26.2.0
122
+ referencing==0.35.1
123
+ regex==2024.11.6
124
+ requests==2.32.3
125
+ rich==13.9.4
126
+ rpds-py==0.21.0
127
+ rsa==4.9
128
+ ruff==0.7.4
129
+ safehttpx==0.1.1
130
+ safetensors==0.4.5
131
+ scikit-learn==1.5.2
132
+ scipy==1.14.1
133
+ semantic-version==2.10.0
134
+ setuptools==75.5.0
135
+ shellingham==1.5.4
136
+ six==1.16.0
137
+ smmap==5.0.1
138
+ sniffio==1.3.1
139
+ soupsieve==2.6
140
+ SQLAlchemy==2.0.36
141
+ stack-data==0.6.3
142
+ starlette==0.41.2
143
+ streamlit==1.40.1
144
+ striprtf==0.0.26
145
+ sympy==1.13.1
146
+ tenacity==8.5.0
147
+ threadpoolctl==3.5.0
148
+ tiktoken==0.8.0
149
+ tokenizers==0.20.3
150
+ toml==0.10.2
151
+ tomlkit==0.12.0
152
+ torch==2.5.1
153
+ tornado==6.4.1
154
+ tqdm==4.67.0
155
+ traitlets==5.14.3
156
+ transformers==4.46.2
157
+ typer==0.13.0
158
+ typing-inspect==0.9.0
159
+ typing_extensions==4.12.2
160
+ tzdata==2024.2
161
+ uritemplate==4.1.1
162
+ urllib3==2.2.3
163
+ uvicorn==0.32.0
164
+ watchdog==6.0.0
165
+ wcwidth==0.2.13
166
+ websockets==12.0
167
+ wrapt==1.16.0
168
+ yarl==1.17.1