Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -148,7 +148,9 @@ def create_bibtex_entry(data):
|
|
| 148 |
bibtex = bibtex.rstrip(',\n') + "\n}"
|
| 149 |
return bibtex
|
| 150 |
|
| 151 |
-
def save_bibtex(
|
|
|
|
|
|
|
| 152 |
with tempfile.NamedTemporaryFile(mode='w', delete=False, suffix='.bib') as temp_file:
|
| 153 |
temp_file.write(bibtex_content)
|
| 154 |
return temp_file.name
|
|
@@ -209,7 +211,7 @@ class CombinedProcessor:
|
|
| 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 =
|
| 213 |
print(top_style)
|
| 214 |
|
| 215 |
#Disambiguation to avoid duplicate ids.
|
|
@@ -217,7 +219,15 @@ class CombinedProcessor:
|
|
| 217 |
|
| 218 |
# Join BibTeX entries with HTML formatting
|
| 219 |
formatted_entries = [html.escape(entry) for entry in bibtex_entries]
|
| 220 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 221 |
|
| 222 |
# Create the processor instance
|
| 223 |
processor = CombinedProcessor()
|
|
@@ -227,7 +237,7 @@ with gr.Blocks(theme='JohnSmith9982/small_and_pretty') as demo:
|
|
| 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.
|
| 231 |
|
| 232 |
export_button = gr.Button("Export BibTeX")
|
| 233 |
export_output = gr.File(label="Exported BibTeX File")
|
|
|
|
| 148 |
bibtex = bibtex.rstrip(',\n') + "\n}"
|
| 149 |
return bibtex
|
| 150 |
|
| 151 |
+
def save_bibtex(combined_content):
|
| 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
|
|
|
|
| 211 |
|
| 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 |
print(top_style)
|
| 216 |
|
| 217 |
#Disambiguation to avoid duplicate ids.
|
|
|
|
| 219 |
|
| 220 |
# Join BibTeX entries with HTML formatting
|
| 221 |
formatted_entries = [html.escape(entry) for entry in bibtex_entries]
|
| 222 |
+
|
| 223 |
+
bibtex_content = "\n\n".join(formatted_entries)
|
| 224 |
+
|
| 225 |
+
# Create a paragraph with the top style information
|
| 226 |
+
style_info = f"<p>Top bibliography style: {top_style} (Mean score: {top_style_score:.6f})</p>"
|
| 227 |
+
|
| 228 |
+
# Combine the style information and BibTeX content
|
| 229 |
+
result = f"{style_info}\n\n{bibtex_content}"
|
| 230 |
+
return result
|
| 231 |
|
| 232 |
# Create the processor instance
|
| 233 |
processor = CombinedProcessor()
|
|
|
|
| 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 |
+
bibtex_output = gr.HTML(label="BibTeX Entries", lines=15)
|
| 241 |
|
| 242 |
export_button = gr.Button("Export BibTeX")
|
| 243 |
export_output = gr.File(label="Exported BibTeX File")
|