PierreBrunelle
commited on
Commit
•
e6e1ceb
1
Parent(s):
4313d11
Update app.py
Browse files
app.py
CHANGED
@@ -53,42 +53,6 @@ t['answer'] = t.response.choices[0].message.content
|
|
53 |
|
54 |
MAX_VIDEO_SIZE_MB = 35
|
55 |
|
56 |
-
def process_and_generate_post(video_file, social_media_type):
|
57 |
-
if not video_file:
|
58 |
-
return "Please upload a video file.", None
|
59 |
-
|
60 |
-
try:
|
61 |
-
# Check video file size
|
62 |
-
video_size = os.path.getsize(video_file) / (1024 * 1024) # Convert to MB
|
63 |
-
if video_size > MAX_VIDEO_SIZE_MB:
|
64 |
-
return f"The video file is larger than {MAX_VIDEO_SIZE_MB} MB. Please upload a smaller file.", None
|
65 |
-
|
66 |
-
# # Insert a video into the table. Pixeltable supports referencing external data sources like URLs
|
67 |
-
t.insert([{
|
68 |
-
"video": video_file,
|
69 |
-
"sm_type": social_media_type
|
70 |
-
}])
|
71 |
-
|
72 |
-
# Retrieve Social media posts
|
73 |
-
social_media_post = t.select(t.answer).tail(1)['answer'][0]
|
74 |
-
|
75 |
-
# Retrieve Audio
|
76 |
-
audio = t.select(t.audio).tail(1)['audio'][0]
|
77 |
-
|
78 |
-
# Retrieve thumbnails
|
79 |
-
thumbnails = frames_view.select(frames_view.frame).tail(4)['frame']
|
80 |
-
|
81 |
-
# Retrieve Pixeltable Table containing all videos and stored data
|
82 |
-
df_output = t.collect().to_pandas()
|
83 |
-
|
84 |
-
#Display content
|
85 |
-
return social_media_post, thumbnails, df_output, audio
|
86 |
-
|
87 |
-
except Exception as e:
|
88 |
-
return f"An error occurred: {str(e)}", None
|
89 |
-
|
90 |
-
MAX_VIDEO_SIZE_MB = 35
|
91 |
-
|
92 |
def process_and_generate_post(video_file, social_media_type):
|
93 |
if not video_file:
|
94 |
return "Please upload a video file.", None
|
@@ -126,29 +90,23 @@ def process_and_generate_post(video_file, social_media_type):
|
|
126 |
# Gradio Interface
|
127 |
import gradio as gr
|
128 |
|
129 |
-
footer_md = """
|
130 |
-
**Key Pixeltable functionalities demonstrated in this example:**
|
131 |
-
|
132 |
-
- Video Data Management: Creating tables and views to store and organize video data.
|
133 |
-
- Automated Video Processing: Extracting frames and audio from videos.
|
134 |
-
- Data Transformation: Computing and storing metadata, transcriptions, and AI-generated content.
|
135 |
-
- AI Integration: Utilizing OpenAI's GPT and Whisper models for transcription and content generation.
|
136 |
-
- Custom Functions: Defining user-defined functions (UDFs) for specialized tasks like prompt construction.
|
137 |
-
- Data Persistence: Storing transformed data and AI outputs for easy retrieval and analysis.
|
138 |
-
- Gradio Integration: Creating an interactive web interface for easy user interaction with Pixeltable's functionalities.
|
139 |
-
|
140 |
-
Powered by Pixeltable and OpenAI (gpt-4o-mini-2024-07-18)
|
141 |
-
"""
|
142 |
-
|
143 |
def gradio_interface():
|
144 |
with gr.Blocks(theme=gr.themes.Monochrome()) as demo:
|
145 |
gr.Markdown(
|
146 |
-
"""
|
147 |
-
<center>
|
148 |
-
<h1>Video to Social Media Post Generator</h1>
|
149 |
<img src="https://raw.githubusercontent.com/pixeltable/pixeltable/main/docs/source/data/pixeltable-logo-large.png" alt="Pixeltable" width="20%" />
|
150 |
-
<
|
151 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
152 |
"""
|
153 |
)
|
154 |
|
@@ -189,10 +147,14 @@ def gradio_interface():
|
|
189 |
inputs=[video_input, social_media_type],
|
190 |
outputs=[output, thumbnail, df_output, audio],
|
191 |
)
|
192 |
-
|
193 |
-
gr.Markdown("---") # Horizontal line for separation
|
194 |
-
gr.Markdown(footer_md)
|
195 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
196 |
return demo
|
197 |
|
198 |
# Launch the Gradio interface
|
|
|
53 |
|
54 |
MAX_VIDEO_SIZE_MB = 35
|
55 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
def process_and_generate_post(video_file, social_media_type):
|
57 |
if not video_file:
|
58 |
return "Please upload a video file.", None
|
|
|
90 |
# Gradio Interface
|
91 |
import gradio as gr
|
92 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
93 |
def gradio_interface():
|
94 |
with gr.Blocks(theme=gr.themes.Monochrome()) as demo:
|
95 |
gr.Markdown(
|
96 |
+
"""<p>
|
|
|
|
|
97 |
<img src="https://raw.githubusercontent.com/pixeltable/pixeltable/main/docs/source/data/pixeltable-logo-large.png" alt="Pixeltable" width="20%" />
|
98 |
+
<h1>Video to Social Media Post Generator</h1>
|
99 |
+
<h3>Key functionalities demonstrated in this example:</h3>
|
100 |
+
</p>
|
101 |
+
<ul>
|
102 |
+
<li><strong>Video Data Management:</strong> Creating tables and views to store and organize video data.</li>
|
103 |
+
<li><strong>Automated Video Processing:</strong> Extracting frames and audio from videos.</li>
|
104 |
+
<li><strong>Data Transformation:</strong> Computing and storing metadata, transcriptions, and AI-generated content.</li>
|
105 |
+
<li><strong>AI Integration:</strong> Utilizing OpenAI's GPT and Whisper models for transcription and content generation.</li>
|
106 |
+
<li><strong>Custom Functions:</strong> Defining user-defined functions (UDFs) for specialized tasks like prompt construction.</li>
|
107 |
+
<li><strong>Data Persistence:</strong> Storing transformed data and AI outputs for easy retrieval and analysis.</li>
|
108 |
+
<li><strong>Gradio Integration:</strong> Creating an interactive web interface for easy user interaction with Pixeltable's functionalities.</li>
|
109 |
+
</ul>
|
110 |
"""
|
111 |
)
|
112 |
|
|
|
147 |
inputs=[video_input, social_media_type],
|
148 |
outputs=[output, thumbnail, df_output, audio],
|
149 |
)
|
|
|
|
|
|
|
150 |
|
151 |
+
gr.HTML(
|
152 |
+
"""
|
153 |
+
<div class="footer">
|
154 |
+
<p>Pixeltable is a declarative interface for working with text, images, embeddings, and even video, enabling you to store, transform, index, and iterate on data. Powered solely by <a href="https://github.com/pixeltable/pixeltable" style="text-decoration: underline;" target="_blank">Pixeltable</a> - running OpenAI (gpt-4o-mini-2024-07-18).</a></p>
|
155 |
+
</div>
|
156 |
+
"""
|
157 |
+
)
|
158 |
return demo
|
159 |
|
160 |
# Launch the Gradio interface
|