Spaces:
Sleeping
Sleeping
File size: 3,785 Bytes
6ea0a57 5a5c774 9ddd5f1 bac6bb8 1ca54c6 5a5c774 1ca54c6 5a5c774 9ddd5f1 5a5c774 1ca54c6 5a5c774 3dbe63f 5a5c774 3dbe63f 6ea0a57 afd01cf 3dbe63f 6ea0a57 3dbe63f 6ea0a57 9ddd5f1 5a5c774 9ddd5f1 afd01cf 5a5c774 1ca54c6 5a5c774 d087957 3dbe63f 6ea0a57 5a5c774 afd01cf 6ea0a57 afd01cf 36f8e89 3dbe63f 6ea0a57 5a5c774 b4bd2f6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 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 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# app.py
import gradio as gr
import os
from presentation_assistant import PresentationAssistant
import tempfile
import shutil
def create_presentation(api_key, files, query, num_slides, export_format="markdown"):
try:
if not api_key.strip():
raise ValueError("Please provide your Gemini API key")
# Create a temporary directory to store uploaded files
with tempfile.TemporaryDirectory() as temp_dir:
# Save uploaded files to temporary directory
file_paths = []
for file in files:
original_filename = os.path.basename(file.name)
file_path = os.path.join(temp_dir, original_filename)
shutil.copy(file.name, file_path)
file_paths.append(file_path)
# Initialize assistant with provided API key
assistant = PresentationAssistant(api_key=api_key)
# Get the presentation content
relevant_content = assistant.analyze_documents(temp_dir, query)
if not relevant_content:
raise ValueError("No relevant content found in documents")
presentation_content = assistant.generate_presentation_content(relevant_content, num_slides)
if not presentation_content:
raise ValueError("Failed to generate presentation content")
# Parse the content
title, subtitle, slides = assistant.parse_presentation_content(presentation_content)
# Create markdown version
assistant.write_presentation_file(title, subtitle, slides)
with open('example.md', 'r', encoding='utf-8') as f:
markdown_content = f.read()
# Create instructions and preview
instructions = f"""
# Your Presentation is Ready! 🎉
## Quick View with Slidev
1. Go to [Slidev Online Editor](https://sli.dev/new)
2. Copy and paste ALL of the content below into the editor
3. Click "Preview" to start the presentation
## Your Presentation Content:
```markdown
{markdown_content}
```
"""
# Create PowerPoint if requested
if export_format == "pptx":
pptx_path = assistant.export_to_pptx(title, subtitle, slides)
return instructions, pptx_path
else:
# Save as markdown file for download
output_path = "presentation.md"
with open(output_path, "w", encoding='utf-8') as f:
f.write(markdown_content)
return instructions, output_path
except Exception as e:
print(f"Error details: {str(e)}")
return f"Error: {str(e)}", None
# Create Gradio interface
iface = gr.Interface(
fn=create_presentation,
inputs=[
gr.Textbox(
label="Gemini API Key",
placeholder="Enter your Gemini API key here",
type="password" # This hides the API key
),
gr.File(file_count="multiple", label="Upload Documents (.txt, .pdf, .md, .doc, .docx)"),
gr.Textbox(label="Instructions"),
gr.Number(label="Number of slides", minimum=1, maximum=20, step=1, value=5),
gr.Radio(["markdown", "pptx"], label="Download Format", value="markdown")
],
outputs=[
gr.Markdown(label="Preview and Instructions"),
gr.File(label="Download Presentation")
],
title="Slide Duck 🐥",
description="""Upload documents and generate a presentation based on their content using AI.
You can preview directly in Slidev's online editor or download in your preferred format."""
)
# Launch the app
iface.launch() |