Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,15 +1,11 @@
|
|
1 |
-
|
2 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
3 |
from pptx import Presentation
|
4 |
from pptx.util import Inches
|
5 |
-
import streamlit as st
|
6 |
import subprocess
|
7 |
import os
|
8 |
-
|
9 |
-
|
10 |
-
except ImportError:
|
11 |
-
print("Transformers library is not installed. Please install it using pip install transformers.")
|
12 |
-
# Content Generation Agent
|
13 |
def generate_content(prompt):
|
14 |
tokenizer = AutoTokenizer.from_pretrained("gpt2")
|
15 |
model = AutoModelForCausalLM.from_pretrained("gpt2")
|
@@ -18,64 +14,49 @@ def generate_content(prompt):
|
|
18 |
text = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
19 |
return text
|
20 |
|
21 |
-
# Slide Design
|
22 |
def create_presentation(content_dict, output_file):
|
23 |
prs = Presentation()
|
24 |
-
#
|
25 |
-
#
|
26 |
-
title_slide_layout = prs.slide_layouts[0]
|
27 |
-
slide = prs.slides.add_slide(title_slide_layout)
|
28 |
-
slide.shapes.title.text = content_dict['title']
|
29 |
-
slide.placeholders[1].text = content_dict['subtitle']
|
30 |
-
# Create content slides
|
31 |
-
for content in content_dict['slides']:
|
32 |
-
content_slide_layout = prs.slide_layouts[1]
|
33 |
-
slide = prs.slides.add_slide(content_slide_layout)
|
34 |
-
slide.shapes.title.text = content['title']
|
35 |
-
slide.placeholders[1].text = content['content']
|
36 |
prs.save(output_file)
|
37 |
|
38 |
-
# Output Conversion
|
39 |
def convert_to_pdf(pptx_file, pdf_file):
|
40 |
subprocess.run(['soffice', '--headless', '--convert-to', 'pdf', pptx_file, '--outdir', os.path.dirname(pdf_file)])
|
41 |
|
42 |
-
#
|
43 |
-
def main():
|
44 |
-
st.title("Presentation Generator")
|
45 |
-
title = st.text_input("Enter presentation title:")
|
46 |
-
subtitle = st.text_input("Enter subtitle:")
|
47 |
-
num_slides = st.number_input("Number of slides", min_value=1, max_value=10, value=1)
|
48 |
slides = []
|
49 |
-
for
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
|
80 |
-
|
81 |
-
main()
|
|
|
1 |
+
import gradio as gr
|
2 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
3 |
from pptx import Presentation
|
4 |
from pptx.util import Inches
|
|
|
5 |
import subprocess
|
6 |
import os
|
7 |
+
|
8 |
+
# Content Generation Function
|
|
|
|
|
|
|
9 |
def generate_content(prompt):
|
10 |
tokenizer = AutoTokenizer.from_pretrained("gpt2")
|
11 |
model = AutoModelForCausalLM.from_pretrained("gpt2")
|
|
|
14 |
text = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
15 |
return text
|
16 |
|
17 |
+
# Slide Design Function
|
18 |
def create_presentation(content_dict, output_file):
|
19 |
prs = Presentation()
|
20 |
+
# Create slides based on content_dict
|
21 |
+
# ...
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
prs.save(output_file)
|
23 |
|
24 |
+
# Output Conversion Function
|
25 |
def convert_to_pdf(pptx_file, pdf_file):
|
26 |
subprocess.run(['soffice', '--headless', '--convert-to', 'pdf', pptx_file, '--outdir', os.path.dirname(pdf_file)])
|
27 |
|
28 |
+
# Main Function
|
29 |
+
def main(title, subtitle, num_slides, slide_prompts):
|
|
|
|
|
|
|
|
|
30 |
slides = []
|
31 |
+
for prompt in slide_prompts:
|
32 |
+
content = generate_content(prompt)
|
33 |
+
slides.append({'title': content, 'content': content})
|
34 |
+
content_dict = {
|
35 |
+
'title': title,
|
36 |
+
'subtitle': subtitle,
|
37 |
+
'slides': slides
|
38 |
+
}
|
39 |
+
pptx_file = "output.pptx"
|
40 |
+
create_presentation(content_dict, pptx_file)
|
41 |
+
pdf_file = "output.pdf"
|
42 |
+
convert_to_pdf(pptx_file, pdf_file)
|
43 |
+
return pptx_file, pdf_file
|
44 |
+
|
45 |
+
# Gradio Interface
|
46 |
+
with gr.Blocks() as demo:
|
47 |
+
gr.Markdown("# Presentation Generator")
|
48 |
+
title = gr.Textbox(label="Presentation Title")
|
49 |
+
subtitle = gr.Textbox(label="Subtitle")
|
50 |
+
num_slides = gr.Number(label="Number of Slides", value=1)
|
51 |
+
slide_prompts = gr.Textbox(label="Slide Prompts (one per line)", lines=5)
|
52 |
+
generate_button = gr.Button("Generate Presentation")
|
53 |
+
output_pptx = gr.File(label="Download PPTX")
|
54 |
+
output_pdf = gr.File(label="Download PDF")
|
55 |
+
|
56 |
+
generate_button.click(
|
57 |
+
main,
|
58 |
+
inputs=[title, subtitle, num_slides, slide_prompts],
|
59 |
+
outputs=[output_pptx, output_pdf]
|
60 |
+
)
|
61 |
|
62 |
+
demo.launch()
|
|