RichardVR's picture
Update app.py
367a152 verified
import gradio as gr
import os
from workflow_logic import run_daily_ai_video_workflow
def run_workflow_and_display_results():
"""
Function to run the workflow and return results for Gradio.
"""
output_messages = []
output_messages.append("Initiating workflow... This may take several minutes (due to Heygen video processing and a hardcoded 8-minute wait).")
try:
workflow_output = run_daily_ai_video_workflow()
if workflow_output['status'] == "success":
output_messages.append("πŸŽ‰ Workflow Completed Successfully!")
output_messages.append("Summary of Results:")
output_messages.append(f"```json\n{json.dumps(workflow_output['results'], indent=2)}\n```") # Format JSON nicely
if workflow_output['results'].get('heygen_video_url'):
output_messages.append(f"Heygen Video URL: {workflow_output['results']['heygen_video_url']}")
# Gradio needs the URL directly for gr.Video
return "\n".join(output_messages), workflow_output['results'].get('heygen_video_url')
else:
output_messages.append(f"Workflow Failed: {workflow_output['message']}")
if workflow_output.get('results'):
output_messages.append("Partial Results:")
output_messages.append(f"```json\n{json.dumps(workflow_output['results'], indent=2)}\n```")
return "\n".join(output_messages), None
except Exception as e:
output_messages.append(f"An unexpected error occurred during workflow execution: {str(e)}")
return "\n".join(output_messages), None
# Gradio Interface
with gr.Blocks() as demo:
gr.Markdown(
"""
# Automated AI Video & Social Media Publisher
This app runs a workflow to generate AI avatar videos based on trending AI news from Hacker News and publishes them to social media platforms via Blotato.
"""
)
gr.Markdown(
"""
**Before running:**
Please ensure you have set the following API keys as **Space Secrets** in your Hugging Face Space settings:
* `OPENAI_API_KEY`
* `HEYGEN_API_KEY`
* `BLOTATO_API_KEY`
You can also set various `HEYGEN_` and `BLOTATO_` specific IDs as environment variables if needed.
"""
)
run_button = gr.Button("πŸš€ Run Workflow Now")
output_text = gr.Textbox(label="Workflow Output", lines=20, interactive=False)
video_output = gr.Video(label="Generated Video Preview", interactive=False)
run_button.click(
fn=run_workflow_and_display_results,
inputs=[],
outputs=[output_text, video_output]
)
# Launch the Gradio app
demo.launch()