Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -25,8 +25,6 @@ bibliography_classifier = pipeline(
|
|
| 25 |
"token-classification", model=bibliography_model, aggregation_strategy="simple", device=device
|
| 26 |
)
|
| 27 |
|
| 28 |
-
style_classifier = pipeline("text-classification", model=bibliography_style, tokenizer=tokenizer, device=device)
|
| 29 |
-
|
| 30 |
# Helper functions
|
| 31 |
def preprocess_text(text):
|
| 32 |
text = re.sub(r'<[^>]+>', '', text)
|
|
@@ -179,8 +177,8 @@ class CombinedProcessor:
|
|
| 179 |
print(entry)
|
| 180 |
entry = re.sub(r'- ?[\n¶] ?', r'', entry)
|
| 181 |
entry = re.sub(r' ?[\n¶] ?', r' ', entry)
|
| 182 |
-
style = pd.DataFrame(style_classifier(entry, truncation=True, padding=True, top_k=1))
|
| 183 |
-
list_style.append(style)
|
| 184 |
entry = re.sub(r'\s*([;:,\.])\s*', r' \1 ', entry)
|
| 185 |
#print(entry)
|
| 186 |
bib_out = bibliography_classifier(entry)
|
|
@@ -207,18 +205,19 @@ class CombinedProcessor:
|
|
| 207 |
bibtex_entry = create_bibtex_entry(bibtex_data)
|
| 208 |
bibtex_entries.append(bibtex_entry)
|
| 209 |
|
| 210 |
-
list_style = pd.concat(list_style)
|
| 211 |
-
list_style = list_style.groupby('label')['score'].mean().sort_values(ascending=False).reset_index()
|
| 212 |
-
top_style = list_style.iloc[0]['label']
|
| 213 |
-
top_style_score = list_style.iloc[0]['score']
|
| 214 |
|
| 215 |
# Create the style information string
|
| 216 |
-
style_info = f"Top bibliography style: {top_style} (Mean score: {top_style_score:.6f})"
|
| 217 |
|
| 218 |
# Join BibTeX entries
|
| 219 |
bibtex_content = "\n\n".join(bibtex_entries)
|
| 220 |
|
| 221 |
-
return style_info, bibtex_content
|
|
|
|
| 222 |
|
| 223 |
# Create the processor instance
|
| 224 |
processor = CombinedProcessor()
|
|
@@ -228,13 +227,12 @@ with gr.Blocks(theme='JohnSmith9982/small_and_pretty') as demo:
|
|
| 228 |
gr.HTML("""<h1 style="text-align:center">Reversed Zotero</h1>""")
|
| 229 |
text_input = gr.Textbox(label="Your text", type="text", lines=10)
|
| 230 |
text_button = gr.Button("Process Text")
|
| 231 |
-
style_output = gr.Textbox(label="Top Style", lines=2)
|
| 232 |
bibtex_output = gr.Textbox(label="BibTeX Entries", lines=15)
|
| 233 |
|
| 234 |
export_button = gr.Button("Export BibTeX")
|
| 235 |
export_output = gr.File(label="Exported BibTeX File")
|
| 236 |
|
| 237 |
-
text_button.click(processor.process, inputs=text_input, outputs=[
|
| 238 |
export_button.click(save_bibtex, inputs=[bibtex_output], outputs=[export_output])
|
| 239 |
|
| 240 |
if __name__ == "__main__":
|
|
|
|
| 25 |
"token-classification", model=bibliography_model, aggregation_strategy="simple", device=device
|
| 26 |
)
|
| 27 |
|
|
|
|
|
|
|
| 28 |
# Helper functions
|
| 29 |
def preprocess_text(text):
|
| 30 |
text = re.sub(r'<[^>]+>', '', text)
|
|
|
|
| 177 |
print(entry)
|
| 178 |
entry = re.sub(r'- ?[\n¶] ?', r'', entry)
|
| 179 |
entry = re.sub(r' ?[\n¶] ?', r' ', entry)
|
| 180 |
+
#style = pd.DataFrame(style_classifier(entry, truncation=True, padding=True, top_k=1))
|
| 181 |
+
#list_style.append(style)
|
| 182 |
entry = re.sub(r'\s*([;:,\.])\s*', r' \1 ', entry)
|
| 183 |
#print(entry)
|
| 184 |
bib_out = bibliography_classifier(entry)
|
|
|
|
| 205 |
bibtex_entry = create_bibtex_entry(bibtex_data)
|
| 206 |
bibtex_entries.append(bibtex_entry)
|
| 207 |
|
| 208 |
+
#list_style = pd.concat(list_style)
|
| 209 |
+
#list_style = list_style.groupby('label')['score'].mean().sort_values(ascending=False).reset_index()
|
| 210 |
+
#top_style = list_style.iloc[0]['label']
|
| 211 |
+
#top_style_score = list_style.iloc[0]['score']
|
| 212 |
|
| 213 |
# Create the style information string
|
| 214 |
+
#style_info = f"Top bibliography style: {top_style} (Mean score: {top_style_score:.6f})"
|
| 215 |
|
| 216 |
# Join BibTeX entries
|
| 217 |
bibtex_content = "\n\n".join(bibtex_entries)
|
| 218 |
|
| 219 |
+
#return style_info, bibtex_content
|
| 220 |
+
return bibtex_content
|
| 221 |
|
| 222 |
# Create the processor instance
|
| 223 |
processor = CombinedProcessor()
|
|
|
|
| 227 |
gr.HTML("""<h1 style="text-align:center">Reversed Zotero</h1>""")
|
| 228 |
text_input = gr.Textbox(label="Your text", type="text", lines=10)
|
| 229 |
text_button = gr.Button("Process Text")
|
|
|
|
| 230 |
bibtex_output = gr.Textbox(label="BibTeX Entries", lines=15)
|
| 231 |
|
| 232 |
export_button = gr.Button("Export BibTeX")
|
| 233 |
export_output = gr.File(label="Exported BibTeX File")
|
| 234 |
|
| 235 |
+
text_button.click(processor.process, inputs=text_input, outputs=[bibtex_output])
|
| 236 |
export_button.click(save_bibtex, inputs=[bibtex_output], outputs=[export_output])
|
| 237 |
|
| 238 |
if __name__ == "__main__":
|