Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -87,6 +87,8 @@ def filter_paragraphs(keyword):
|
|
87 |
if not keyword:
|
88 |
paragraph1 = [f"Paragraph {i+1}: {p[:100]}..." for i, p in enumerate(stored_paragraphs_1)]
|
89 |
paragraph2 = [f"Paragraph {i+1}: {p[:100]}..." for i, p in enumerate(stored_paragraphs_2)]
|
|
|
|
|
90 |
return gr.update(choices=paragraph1, value=None), gr.update(choices=paragraph2, value=None) # No keyword entered, return original list
|
91 |
filter_paragraphs_1 = [p for p in stored_paragraphs_1 if keyword.lower() in p.lower()]
|
92 |
filter_paragraphs_2 = [p for p in stored_paragraphs_2 if keyword.lower() in p.lower()]
|
@@ -115,7 +117,7 @@ def filtered_close_paragraph(p, keyword, pdf):
|
|
115 |
def process_paragraph_1_sum(paragraph):
|
116 |
try:
|
117 |
paragraph_index = int(paragraph.split(':')[0].replace('Paragraph ', '')) - 1
|
118 |
-
selected_paragraph =
|
119 |
summary = summarize_text(selected_paragraph)
|
120 |
return summary
|
121 |
except (IndexError, ValueError):
|
@@ -123,7 +125,7 @@ def process_paragraph_1_sum(paragraph):
|
|
123 |
def process_paragraph_1_sent(paragraph):
|
124 |
try:
|
125 |
paragraph_index = int(paragraph.split(':')[0].replace('Paragraph ', '')) - 1
|
126 |
-
selected_paragraph =
|
127 |
results = text_to_sentiment(selected_paragraph, True, False)
|
128 |
if isinstance(results, list) and isinstance(results[0], list):
|
129 |
# We unpack the list of dictionaries to get all labels
|
@@ -137,7 +139,7 @@ def process_paragraph_1_sent(paragraph):
|
|
137 |
def process_paragraph_1_sent_tone(paragraph):
|
138 |
try:
|
139 |
paragraph_index = int(paragraph.split(':')[0].replace('Paragraph ', '')) - 1
|
140 |
-
selected_paragraph =
|
141 |
fin_spans = fin_ext(selected_paragraph)
|
142 |
return fin_spans
|
143 |
except (IndexError, ValueError):
|
@@ -145,7 +147,7 @@ def process_paragraph_1_sent_tone(paragraph):
|
|
145 |
def process_paragraph_1_sent_tone_bis(paragraph):
|
146 |
try:
|
147 |
paragraph_index = int(paragraph.split(':')[0].replace('Paragraph ', '')) - 1
|
148 |
-
selected_paragraph =
|
149 |
fin_spans = fin_ext_bis(selected_paragraph)
|
150 |
return fin_spans
|
151 |
except (IndexError, ValueError):
|
@@ -153,7 +155,7 @@ def process_paragraph_1_sent_tone_bis(paragraph):
|
|
153 |
def process_paragraph_2_sum(paragraph):
|
154 |
try:
|
155 |
paragraph_index = int(paragraph.split(':')[0].replace('Paragraph ', '')) - 1
|
156 |
-
selected_paragraph =
|
157 |
summary = summarize_text(selected_paragraph)
|
158 |
return summary
|
159 |
except (IndexError, ValueError):
|
@@ -161,7 +163,7 @@ def process_paragraph_2_sum(paragraph):
|
|
161 |
def process_paragraph_2_sent(paragraph):
|
162 |
try:
|
163 |
paragraph_index = int(paragraph.split(':')[0].replace('Paragraph ', '')) - 1
|
164 |
-
selected_paragraph =
|
165 |
results = text_to_sentiment(selected_paragraph, True, False)
|
166 |
if isinstance(results, list) and isinstance(results[0], list):
|
167 |
# We unpack the list of dictionaries to get all labels
|
@@ -174,7 +176,7 @@ def process_paragraph_2_sent(paragraph):
|
|
174 |
def process_paragraph_2_sent_tone(paragraph):
|
175 |
try:
|
176 |
paragraph_index = int(paragraph.split(':')[0].replace('Paragraph ', '')) - 1
|
177 |
-
selected_paragraph =
|
178 |
fin_spans = fin_ext(selected_paragraph)
|
179 |
return fin_spans
|
180 |
except (IndexError, ValueError):
|
@@ -182,7 +184,7 @@ def process_paragraph_2_sent_tone(paragraph):
|
|
182 |
def process_paragraph_2_sent_tone_bis(paragraph):
|
183 |
try:
|
184 |
paragraph_index = int(paragraph.split(':')[0].replace('Paragraph ', '')) - 1
|
185 |
-
selected_paragraph =
|
186 |
fin_spans = fin_ext_bis(selected_paragraph)
|
187 |
return fin_spans
|
188 |
except (IndexError, ValueError):
|
@@ -193,14 +195,14 @@ def get_pdf_files(folder):
|
|
193 |
def show1(paragraph):
|
194 |
try:
|
195 |
paragraph_index = int(paragraph.split(':')[0].replace('Paragraph ', '')) - 1
|
196 |
-
selected_paragraph =
|
197 |
return selected_paragraph
|
198 |
except (IndexError, ValueError):
|
199 |
return "Error"
|
200 |
def show2(paragraph):
|
201 |
try:
|
202 |
paragraph_index = int(paragraph.split(':')[0].replace('Paragraph ', '')) - 1
|
203 |
-
selected_paragraph =
|
204 |
return selected_paragraph
|
205 |
except (IndexError, ValueError):
|
206 |
return "Error"
|
@@ -508,7 +510,9 @@ with gr.Blocks(theme='gradio/soft',js=js_func) as demo:
|
|
508 |
# Extract paragraphs from PDFs and update dropdowns
|
509 |
def update_paragraphs(pdf1, pdf2):
|
510 |
global stored_paragraphs_1, stored_paragraphs_2
|
|
|
511 |
stored_paragraphs_1, stored_paragraphs_2 = extract_and_paragraph(pdf1, pdf2, True)
|
|
|
512 |
updated_dropdown_1 = [f"Paragraph {i+1}: {p[:100]}..." for i, p in enumerate(stored_paragraphs_1)]
|
513 |
updated_dropdown_2 = [f"Paragraph {i+1}: {p[:100]}..." for i, p in enumerate(stored_paragraphs_2)]
|
514 |
return gr.update(choices=updated_dropdown_1), gr.update(choices=updated_dropdown_2)
|
|
|
87 |
if not keyword:
|
88 |
paragraph1 = [f"Paragraph {i+1}: {p[:100]}..." for i, p in enumerate(stored_paragraphs_1)]
|
89 |
paragraph2 = [f"Paragraph {i+1}: {p[:100]}..." for i, p in enumerate(stored_paragraphs_2)]
|
90 |
+
filter_paragraphs_1 = stored_paragraphs_1
|
91 |
+
filter_paragraphs_2 = stored_paragraphs_2
|
92 |
return gr.update(choices=paragraph1, value=None), gr.update(choices=paragraph2, value=None) # No keyword entered, return original list
|
93 |
filter_paragraphs_1 = [p for p in stored_paragraphs_1 if keyword.lower() in p.lower()]
|
94 |
filter_paragraphs_2 = [p for p in stored_paragraphs_2 if keyword.lower() in p.lower()]
|
|
|
117 |
def process_paragraph_1_sum(paragraph):
|
118 |
try:
|
119 |
paragraph_index = int(paragraph.split(':')[0].replace('Paragraph ', '')) - 1
|
120 |
+
selected_paragraph = filter_paragraphs_1[paragraph_index]
|
121 |
summary = summarize_text(selected_paragraph)
|
122 |
return summary
|
123 |
except (IndexError, ValueError):
|
|
|
125 |
def process_paragraph_1_sent(paragraph):
|
126 |
try:
|
127 |
paragraph_index = int(paragraph.split(':')[0].replace('Paragraph ', '')) - 1
|
128 |
+
selected_paragraph = filter_paragraphs_1[paragraph_index]
|
129 |
results = text_to_sentiment(selected_paragraph, True, False)
|
130 |
if isinstance(results, list) and isinstance(results[0], list):
|
131 |
# We unpack the list of dictionaries to get all labels
|
|
|
139 |
def process_paragraph_1_sent_tone(paragraph):
|
140 |
try:
|
141 |
paragraph_index = int(paragraph.split(':')[0].replace('Paragraph ', '')) - 1
|
142 |
+
selected_paragraph = filter_paragraphs_1[paragraph_index]
|
143 |
fin_spans = fin_ext(selected_paragraph)
|
144 |
return fin_spans
|
145 |
except (IndexError, ValueError):
|
|
|
147 |
def process_paragraph_1_sent_tone_bis(paragraph):
|
148 |
try:
|
149 |
paragraph_index = int(paragraph.split(':')[0].replace('Paragraph ', '')) - 1
|
150 |
+
selected_paragraph = filter_paragraphs_1[paragraph_index]
|
151 |
fin_spans = fin_ext_bis(selected_paragraph)
|
152 |
return fin_spans
|
153 |
except (IndexError, ValueError):
|
|
|
155 |
def process_paragraph_2_sum(paragraph):
|
156 |
try:
|
157 |
paragraph_index = int(paragraph.split(':')[0].replace('Paragraph ', '')) - 1
|
158 |
+
selected_paragraph = filter_paragraphs_2[paragraph_index]
|
159 |
summary = summarize_text(selected_paragraph)
|
160 |
return summary
|
161 |
except (IndexError, ValueError):
|
|
|
163 |
def process_paragraph_2_sent(paragraph):
|
164 |
try:
|
165 |
paragraph_index = int(paragraph.split(':')[0].replace('Paragraph ', '')) - 1
|
166 |
+
selected_paragraph = filter_paragraphs_2[paragraph_index]
|
167 |
results = text_to_sentiment(selected_paragraph, True, False)
|
168 |
if isinstance(results, list) and isinstance(results[0], list):
|
169 |
# We unpack the list of dictionaries to get all labels
|
|
|
176 |
def process_paragraph_2_sent_tone(paragraph):
|
177 |
try:
|
178 |
paragraph_index = int(paragraph.split(':')[0].replace('Paragraph ', '')) - 1
|
179 |
+
selected_paragraph = filter_paragraphs_2[paragraph_index]
|
180 |
fin_spans = fin_ext(selected_paragraph)
|
181 |
return fin_spans
|
182 |
except (IndexError, ValueError):
|
|
|
184 |
def process_paragraph_2_sent_tone_bis(paragraph):
|
185 |
try:
|
186 |
paragraph_index = int(paragraph.split(':')[0].replace('Paragraph ', '')) - 1
|
187 |
+
selected_paragraph = filter_paragraphs_2[paragraph_index]
|
188 |
fin_spans = fin_ext_bis(selected_paragraph)
|
189 |
return fin_spans
|
190 |
except (IndexError, ValueError):
|
|
|
195 |
def show1(paragraph):
|
196 |
try:
|
197 |
paragraph_index = int(paragraph.split(':')[0].replace('Paragraph ', '')) - 1
|
198 |
+
selected_paragraph = filter_paragraphs_1[paragraph_index]
|
199 |
return selected_paragraph
|
200 |
except (IndexError, ValueError):
|
201 |
return "Error"
|
202 |
def show2(paragraph):
|
203 |
try:
|
204 |
paragraph_index = int(paragraph.split(':')[0].replace('Paragraph ', '')) - 1
|
205 |
+
selected_paragraph = filter_paragraphs_2[paragraph_index]
|
206 |
return selected_paragraph
|
207 |
except (IndexError, ValueError):
|
208 |
return "Error"
|
|
|
510 |
# Extract paragraphs from PDFs and update dropdowns
|
511 |
def update_paragraphs(pdf1, pdf2):
|
512 |
global stored_paragraphs_1, stored_paragraphs_2
|
513 |
+
global filter_paragraphs_1, filter_paragraphs_2
|
514 |
stored_paragraphs_1, stored_paragraphs_2 = extract_and_paragraph(pdf1, pdf2, True)
|
515 |
+
filter_paragraphs_1, filter_paragraphs_2 = stored_paragraphs_1, stored_paragraphs_2
|
516 |
updated_dropdown_1 = [f"Paragraph {i+1}: {p[:100]}..." for i, p in enumerate(stored_paragraphs_1)]
|
517 |
updated_dropdown_2 = [f"Paragraph {i+1}: {p[:100]}..." for i, p in enumerate(stored_paragraphs_2)]
|
518 |
return gr.update(choices=updated_dropdown_1), gr.update(choices=updated_dropdown_2)
|