fhmsf commited on
Commit
3d0f58b
·
verified ·
1 Parent(s): 92ebd3a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +60 -42
app.py CHANGED
@@ -6,13 +6,6 @@ import requests
6
 
7
  from pypdf import PdfReader
8
  from sentence_transformers import SentenceTransformer
9
- from getpass import getpass
10
-
11
- ################################################################################
12
- # 0. Optionally Prompt for Gemini Key in Colab (SECURE)
13
- ################################################################################
14
- # key_input = getpass("Enter your Gemini API key: ")
15
- # os.environ["GEMINI_API_KEY"] = key_input
16
 
17
  ################################################################################
18
  # 1. PDF Parsing and Chunking
@@ -25,7 +18,7 @@ def extract_pdf_text(pdf_file) -> str:
25
  all_text.append(text.strip())
26
  return "\n".join(all_text)
27
 
28
- def chunk_text(text, chunk_size=400, overlap=50):
29
  words = text.split()
30
  chunks = []
31
  start = 0
@@ -123,7 +116,7 @@ def process_pdf(pdf_file):
123
  if not text:
124
  return None, "No text found in PDF."
125
 
126
- chunks = chunk_text(text, chunk_size=400, overlap=50)
127
  if not chunks:
128
  return None, "No valid text to chunk."
129
 
@@ -142,63 +135,88 @@ def chat_with_paper(query, state):
142
 
143
  demo_theme = gr.themes.Soft(primary_hue="slate")
144
 
145
- # Custom CSS changes:
146
  # 1. Lightest blue background
147
  # 2. Green buttons
148
- # 3. Thick black border around the entire interface
149
- # 4. Large, bold, centered title
150
- # 5. Welcome message directly under the title
151
  css_code = """
152
- /* Make the background a very light blue */
153
  body {
154
- background-color: #E6F7FF; /* Lightest blue shade, tweak as needed */
 
 
155
  }
156
 
157
- /* Add a thick black border around the Gradio interface container */
158
  .block > .inside {
159
- border: 4px solid black; /* thick black border */
160
- padding: 20px; /* some spacing from edges */
161
- border-radius: 10px; /* optional rounding corners */
162
- background-color: #FFFFFF; /* keep container white so text is clear */
 
 
163
  }
164
 
165
- /* Title heading: big, bold, centered */
166
- #title-heading {
167
- text-align: center;
168
- font-size: 2.8rem; /* bigger font than before */
169
- font-weight: 900; /* extra bold */
170
- margin-bottom: 10px;
171
- margin-top: 0;
172
  }
173
 
174
- /* Welcome text right under the title */
175
- #welcome-text {
176
- text-align: center;
177
- font-size: 1.3rem;
178
- color: #444;
179
- margin-bottom: 25px;
180
- margin-top: 0.5rem;
181
- font-weight: 500;
182
  }
183
 
184
- /* Buttons should be green */
185
  button {
186
- background-color: #3CB371 !important; /* mediumseagreen or any green shade */
187
- color: #fff !important;
188
  border: none !important;
189
  font-weight: 600 !important;
190
  cursor: pointer;
191
  }
192
 
193
- /* Button hover effect */
194
  button:hover {
195
- background-color: #2E8B57 !important; /* slightly darker green on hover */
 
 
 
 
 
 
 
 
 
 
 
 
196
  }
197
  """
198
 
199
  with gr.Blocks(theme=demo_theme, css=css_code) as demo:
200
- gr.Markdown("<div id='title-heading'>AI-Powered Personal Research Assistant</div>")
201
- gr.Markdown("<div id='welcome-text'>Welcome! How may I help you?</div>")
 
 
 
 
 
 
 
 
 
 
 
202
 
203
  state = gr.State()
204
 
 
6
 
7
  from pypdf import PdfReader
8
  from sentence_transformers import SentenceTransformer
 
 
 
 
 
 
 
9
 
10
  ################################################################################
11
  # 1. PDF Parsing and Chunking
 
18
  all_text.append(text.strip())
19
  return "\n".join(all_text)
20
 
21
+ def chunk_text(text, chunk_size=300, overlap=50):
22
  words = text.split()
23
  chunks = []
24
  start = 0
 
116
  if not text:
117
  return None, "No text found in PDF."
118
 
119
+ chunks = chunk_text(text, chunk_size=300, overlap=50)
120
  if not chunks:
121
  return None, "No valid text to chunk."
122
 
 
135
 
136
  demo_theme = gr.themes.Soft(primary_hue="slate")
137
 
138
+ # Custom CSS:
139
  # 1. Lightest blue background
140
  # 2. Green buttons
141
+ # 3. Thick black border, centered content
142
+ # 4. Large, bold, center-aligned title
143
+ # 5. Representative icon at top, bigger font for welcome text
144
  css_code = """
 
145
  body {
146
+ background-color: #E6F7FF !important; /* Lightest blue */
147
+ margin: 0;
148
+ padding: 0;
149
  }
150
 
151
+ /* Center the entire Gradio container and give a thick black border */
152
  .block > .inside {
153
+ margin: auto !important;
154
+ max-width: 900px !important; /* You can increase/decrease the max-width for your preference */
155
+ border: 4px solid black !important; /* Thick black border */
156
+ border-radius: 10px !important;
157
+ background-color: #FFFFFF !important; /* White container for clarity */
158
+ padding: 20px !important;
159
  }
160
 
161
+ /* Title heading: bigger, bolder, centered */
162
+ #app-title {
163
+ text-align: center !important;
164
+ font-size: 3rem !important;
165
+ font-weight: 900 !important;
166
+ margin-bottom: 0.5rem !important;
167
+ margin-top: 0.5rem !important;
168
  }
169
 
170
+ /* Welcome text: slightly smaller, but still bold, centered */
171
+ #app-welcome {
172
+ text-align: center !important;
173
+ font-size: 1.5rem !important;
174
+ color: #444 !important;
175
+ margin-bottom: 25px !important;
176
+ font-weight: 700 !important;
 
177
  }
178
 
179
+ /* Buttons: green background, white text */
180
  button {
181
+ background-color: #3CB371 !important; /* Medium sea green */
182
+ color: #ffffff !important;
183
  border: none !important;
184
  font-weight: 600 !important;
185
  cursor: pointer;
186
  }
187
 
188
+ /* Button hover effect: darker green */
189
  button:hover {
190
+ background-color: #2E8B57 !important;
191
+ }
192
+
193
+ /* Optional: center the text in textboxes, if you like */
194
+ textarea, input[type="text"] {
195
+ text-align: center !important;
196
+ }
197
+
198
+ /* Icon container styling */
199
+ #icon-container {
200
+ text-align: center !important;
201
+ margin-top: 1rem !important;
202
+ margin-bottom: 1rem !important;
203
  }
204
  """
205
 
206
  with gr.Blocks(theme=demo_theme, css=css_code) as demo:
207
+ # Representative icon/image at the top
208
+ # Replace the 'src' with any other icon URL you prefer
209
+ gr.Markdown("""
210
+ <div id="icon-container">
211
+ <img src="https://i.ibb.co/3Wp3yBZ/ai-icon.png" alt="AI icon" style="width:100px;">
212
+ </div>
213
+ """)
214
+
215
+ # App title (large, bold, centered)
216
+ gr.Markdown("<div id='app-title'>AI-Powered Personal Research Assistant</div>")
217
+
218
+ # Welcome text right under the title
219
+ gr.Markdown("<div id='app-welcome'>Welcome! How may I help you?</div>")
220
 
221
  state = gr.State()
222