from gradio_client import Client
import gradio as gr
import os
import random
import datetime
from huggingface_hub import hf_api
def check_password(username, password):
if password == os.environ["ACCESS"]:
return True
else:
return False
def func(file, number_of_pages, secret):
if secret != os.environ["ACCESS"]:
return "Wrong password, please try again"
space_runtime = hf_api.get_space_runtime("ByMatthew/deckify_private", token=read_key)
print(f"Space runtime: {space_runtime}")
if not space_runtime.status == "RUNNING": # might need to check lowercase or something
space_runtime_after_restart = hf_api.restart_space("ByMatthew/deckify_private", token=read_key)
print(f"Space runtime after restart: {space_runtime_after_restart}")
client = Client("ByMatthew/deckify_private", hf_token=read_key)
print(f"Client: {client}")
output = client.predict(file, number_of_pages)
if "Error" in output:
return output
# generate a random sequence of numbers
# s = "".join([str(random.randint(0, 9)) for i in range(10)])
# with open(f"{s}.tex", "w", encoding="utf-8") as f:
# f.write(text)
date_string = datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S")
temp_string = "% The following slide is generated with [[SCIDECK]](https://huggingface.co/spaces/Nauryzbay/Scideck)"
temp_string += "\n% Generated on " + date_string
temp_string += "\n%" + "-"*100 + "\n"
output = temp_string + output
return output
def upload_file(file):
return file.name
# 📝 If you get an error message, you can send me email with the PDF file attached to this email address: nkoisheke [at] ethz [dot] ch, and I will generate the slides for you. If there are any other issues or questions, please do not hesitate to contact me 🤗
description = r"""
SCIDECK is a tool that allows you to convert your PDF files into a presentation deck.
❗️❗️❗️[Important] Instructions:
1️⃣ Upload the PDF document: Select the PDF file you want to convert into slides.
2️⃣ Specify the number of pages: Indicate the range of pages you'd like to include in the slide generation. Set it to 0 if you want to include all pages.
3️⃣ Enter the password provided in the invite email.
4️⃣ Click the Generate button: Initiate the slide generation process by clicking the designated "Generate" button.
5️⃣ Be patient 🙂: Generating the slides could take between 1 minute and 5 minutes.
🖼️ Some examples of slides generated using SCIDECK are shown below:
1. Batch Normalization: Accelerating Deep Network Training by Reducing Internal Covariate Shift [[Paper]](https://arxiv.org/pdf/1502.03167.pdf) [[Slides]](https://drive.google.com/file/d/1Zt5FFH0nKxut-LyEr9pNAIdtgR_lBtIj/view?usp=sharing)
2. Attention Is All You Need [[Paper]](https://arxiv.org/pdf/1706.03762.pdf) [[Slides]](https://drive.google.com/file/d/1xKgohh_QKV9pD_XjDuXR566h0VJ1S7WI/view?usp=sharing)
3. Denoising Diffusion Probabilistic Models [[Paper]](https://arxiv.org/pdf/2006.11239.pdf) [[Slides]](https://drive.google.com/file/d/1D2ZfoJpHR3kP0JdsYyjxUq-vjVMV-KTO/view?usp=sharing)
ver 0.1
"""
read_key = os.environ.get("HF_TOKEN", None)
if __name__ == "__main__":
# client = Client.duplicate("ByMatthew/deckify_private", hf_token=read_key)
temp = " SCIDECK: Generate slides (LaTeX Beamer) from PDF
"
with gr.Blocks() as demo:
gr.Markdown(temp)
gr.Image("demo.png", width=600, show_download_button=False, show_label=False)
gr.Markdown(description)
file_output = gr.File()
upload_button = gr.UploadButton("Click to Upload a PDF File", file_types=["file"], file_count="single", size="sm")
upload_button.upload(upload_file, upload_button, file_output)
number_of_pages = gr.Number(label="Number of pages")
secret = gr.Textbox(label="Password", type="password")
output = gr.Textbox(label="Output", show_copy_button=True, interactive=False)
greet_btn = gr.Button("Generate slides")
greet_btn.click(fn=func, inputs=[upload_button, number_of_pages, secret], outputs=output, api_name="greet")
demo.queue(max_size=5)
demo.launch()