Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Sami commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import io
|
| 2 |
+
import shutil
|
| 3 |
+
import tarfile
|
| 4 |
+
import tempfile
|
| 5 |
+
import uuid
|
| 6 |
+
|
| 7 |
+
import gradio as gr
|
| 8 |
+
import requests
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def convert_tar_to_zip(arxiv_url):
|
| 12 |
+
latex_source_url = (arxiv_url.replace('/abs/', '/e-print/')
|
| 13 |
+
.replace('arxiv.org', 'export.arxiv.org'))
|
| 14 |
+
|
| 15 |
+
# Fetch the latex source as .tar.gz file
|
| 16 |
+
tar_file = requests.get(latex_source_url).content
|
| 17 |
+
with tarfile.open(fileobj=io.BytesIO(tar_file)) as tar:
|
| 18 |
+
with tempfile.TemporaryDirectory() as temp_dir:
|
| 19 |
+
# Extract the tar file to a temporary directory
|
| 20 |
+
tar.extractall(temp_dir)
|
| 21 |
+
|
| 22 |
+
# Create a zip file from the extracted tar file
|
| 23 |
+
filename = str(uuid.uuid4())
|
| 24 |
+
zip_name = f'{filename}'
|
| 25 |
+
shutil.make_archive(filename, 'zip', temp_dir)
|
| 26 |
+
|
| 27 |
+
return {'zip_url': f'{zip_name}.zip'}
|
| 28 |
+
|
| 29 |
+
inputs = gr.Textbox(label="URL")
|
| 30 |
+
|
| 31 |
+
title = "Conversion Engine for Arxiv Latex Tar to Zip"
|
| 32 |
+
description = "Enter the URL of the Arxiv paper"
|
| 33 |
+
|
| 34 |
+
gr.Interface(convert_tar_to_zip, inputs, "json", title=title, description=description).launch()
|