PierreBrunelle
commited on
Commit
•
4313d11
1
Parent(s):
bbaf99c
Update app.py
Browse files
app.py
CHANGED
@@ -53,6 +53,42 @@ 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
|
@@ -90,6 +126,20 @@ def process_and_generate_post(video_file, social_media_type):
|
|
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(
|
@@ -139,6 +189,9 @@ def gradio_interface():
|
|
139 |
inputs=[video_input, social_media_type],
|
140 |
outputs=[output, thumbnail, df_output, audio],
|
141 |
)
|
|
|
|
|
|
|
142 |
|
143 |
return demo
|
144 |
|
|
|
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 |
# 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(
|
|
|
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 |
|