Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -148,9 +148,7 @@ def create_bibtex_entry(data):
|
|
| 148 |
bibtex = bibtex.rstrip(',\n') + "\n}"
|
| 149 |
return bibtex
|
| 150 |
|
| 151 |
-
def save_bibtex(
|
| 152 |
-
# Extract BibTeX content (remove the HTML paragraph)
|
| 153 |
-
bibtex_content = re.sub(r'<p>.*?</p>\s*', '', combined_content, flags=re.DOTALL)
|
| 154 |
with tempfile.NamedTemporaryFile(mode='w', delete=False, suffix='.bib') as temp_file:
|
| 155 |
temp_file.write(bibtex_content)
|
| 156 |
return temp_file.name
|
|
@@ -212,22 +210,15 @@ class CombinedProcessor:
|
|
| 212 |
list_style = pd.concat(list_style)
|
| 213 |
list_style = list_style.groupby('label')['score'].mean().sort_values(ascending=False).reset_index()
|
| 214 |
top_style = list_style.iloc[0]['label']
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
#Disambiguation to avoid duplicate ids.
|
| 218 |
-
bibtex_entries = disambiguate_bibtex_ids(bibtex_entries)
|
| 219 |
-
|
| 220 |
-
# Join BibTeX entries with HTML formatting
|
| 221 |
-
formatted_entries = [html.escape(entry) for entry in bibtex_entries]
|
| 222 |
|
| 223 |
-
|
|
|
|
| 224 |
|
| 225 |
-
#
|
| 226 |
-
|
| 227 |
|
| 228 |
-
|
| 229 |
-
result = f"{style_info}\n\n{bibtex_content}"
|
| 230 |
-
return result
|
| 231 |
|
| 232 |
# Create the processor instance
|
| 233 |
processor = CombinedProcessor()
|
|
@@ -237,12 +228,13 @@ with gr.Blocks(theme='JohnSmith9982/small_and_pretty') as demo:
|
|
| 237 |
gr.HTML("""<h1 style="text-align:center">Reversed Zotero</h1>""")
|
| 238 |
text_input = gr.Textbox(label="Your text", type="text", lines=10)
|
| 239 |
text_button = gr.Button("Process Text")
|
| 240 |
-
|
|
|
|
| 241 |
|
| 242 |
export_button = gr.Button("Export BibTeX")
|
| 243 |
export_output = gr.File(label="Exported BibTeX File")
|
| 244 |
|
| 245 |
-
text_button.click(processor.process, inputs=text_input, outputs=[bibtex_output])
|
| 246 |
export_button.click(save_bibtex, inputs=[bibtex_output], outputs=[export_output])
|
| 247 |
|
| 248 |
if __name__ == "__main__":
|
|
|
|
| 148 |
bibtex = bibtex.rstrip(',\n') + "\n}"
|
| 149 |
return bibtex
|
| 150 |
|
| 151 |
+
def save_bibtex(bibtex_content):
|
|
|
|
|
|
|
| 152 |
with tempfile.NamedTemporaryFile(mode='w', delete=False, suffix='.bib') as temp_file:
|
| 153 |
temp_file.write(bibtex_content)
|
| 154 |
return temp_file.name
|
|
|
|
| 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 |
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=[style_output, bibtex_output])
|
| 238 |
export_button.click(save_bibtex, inputs=[bibtex_output], outputs=[export_output])
|
| 239 |
|
| 240 |
if __name__ == "__main__":
|