File size: 5,661 Bytes
6fc3143
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import streamlit as st
import requests
import time
import base64
from pathlib import Path

# Page config
st.set_page_config(
    page_title="Vidsimplify - AI Video Generator",
    page_icon="🎬",
    layout="wide",
    initial_sidebar_state="expanded"
)

# Custom CSS for better aesthetics
st.markdown("""
<style>
    .stApp {
        background-color: #0e1117;
        color: #fafafa;
    }
    .stButton>button {
        background-color: #ff4b4b;
        color: white;
        border-radius: 20px;
        padding: 10px 24px;
        font-weight: bold;
        border: none;
        transition: all 0.3s ease;
    }
    .stButton>button:hover {
        background-color: #ff3333;
        transform: scale(1.05);
    }
    .stTextInput>div>div>input {
        border-radius: 10px;
    }
    .stTextArea>div>div>textarea {
        border-radius: 10px;
    }
    .css-1d391kg {
        padding-top: 3rem;
    }
</style>
""", unsafe_allow_html=True)

# Sidebar
with st.sidebar:
    st.title("🎬 Vidsimplify")
    st.markdown("---")
    st.markdown("### Configuration")
    api_url = st.text_input("API URL", value="http://localhost:8003")
    
    st.markdown("### Settings")
    quality = st.selectbox("Quality", ["low", "medium", "high", "ultra"], index=2)
    category = st.selectbox("Category", ["tech_system", "product_startup", "mathematical"], index=0)
    
    st.markdown("---")
    st.markdown("### About")
    st.info("Generate educational animation videos from text, blogs, or PDFs using Manim and AI.")

# Main content
st.title("AI Video Generator")
st.markdown("Turn your content into engaging animations in minutes.")

# Input tabs
tab1, tab2, tab3 = st.tabs(["πŸ“ Text / Script", "πŸ”— Blog / URL", "πŸ“„ PDF Document"])

input_type = "text"
input_data = ""

with tab1:
    st.header("Text Input")
    st.markdown("Paste your script, blog post, or long text here.")
    text_input = st.text_area("Content", height=300, placeholder="Enter your text here...")
    if text_input:
        input_type = "text"
        input_data = text_input

with tab2:
    st.header("URL Input")
    st.markdown("Enter the URL of a blog post or article.")
    url_input = st.text_input("URL", placeholder="https://example.com/blog-post")
    if url_input:
        input_type = "url"
        input_data = url_input

with tab3:
    st.header("PDF Upload")
    st.markdown("Upload a PDF document to generate a video from.")
    uploaded_file = st.file_uploader("Choose a PDF file", type="pdf")
    if uploaded_file:
        input_type = "pdf"
        # Convert PDF to base64
        bytes_data = uploaded_file.getvalue()
        base64_pdf = base64.b64encode(bytes_data).decode('utf-8')
        input_data = base64_pdf

# Generate button
if st.button("Generate Video", type="primary", use_container_width=True):
    if not input_data:
        st.error("Please provide input data.")
    else:
        try:
            with st.spinner("Submitting job to API..."):
                payload = {
                    "input_type": input_type,
                    "input_data": input_data,
                    "quality": quality,
                    "category": category
                }
                
                response = requests.post(f"{api_url}/api/videos", json=payload)
                
                if response.status_code == 200:
                    job_data = response.json()
                    job_id = job_data["job_id"]
                    st.success(f"Job started! ID: {job_id}")
                    
                    # Polling for status
                    progress_bar = st.progress(0)
                    status_text = st.empty()
                    video_placeholder = st.empty()
                    
                    while True:
                        status_response = requests.get(f"{api_url}/api/jobs/{job_id}")
                        if status_response.status_code == 200:
                            status_data = status_response.json()
                            status = status_data["status"]
                            progress = status_data.get("progress", {})
                            percentage = progress.get("percentage", 0)
                            message = progress.get("message", "Processing...")
                            
                            progress_bar.progress(percentage / 100)
                            status_text.info(f"Status: {status.upper()} - {message}")
                            
                            if status == "completed":
                                st.balloons()
                                status_text.success("Video generation completed!")
                                
                                # Display video
                                video_url = f"{api_url}/api/videos/{job_id}"
                                st.video(video_url)
                                break
                            
                            elif status == "failed":
                                error_msg = status_data.get("error", "Unknown error")
                                status_text.error(f"Job failed: {error_msg}")
                                break
                            
                        time.sleep(2)
                else:
                    st.error(f"Failed to start job: {response.text}")
                    
        except requests.exceptions.ConnectionError:
            st.error(f"Could not connect to API at {api_url}. Is the server running?")
        except Exception as e:
            st.error(f"An error occurred: {str(e)}")

# Footer
st.markdown("---")
st.markdown("Built with Streamlit and Manimator")