File size: 2,715 Bytes
367a152
 
 
81b8ab0
367a152
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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()