Update app.py
Browse files
app.py
CHANGED
@@ -70,7 +70,7 @@ def extract_json_from_markdown(markdown_text):
|
|
70 |
|
71 |
|
72 |
@spaces.GPU
|
73 |
-
def
|
74 |
messages = [
|
75 |
{"role": "user", "content": [
|
76 |
{"type": "image"},
|
@@ -91,8 +91,8 @@ def generate__image_desc(image):
|
|
91 |
return html_output
|
92 |
|
93 |
@spaces.GPU
|
94 |
-
def generate_journal_infographics(
|
95 |
-
prompt = f"Generate daily journal inforgraphics using html for the following:\n\n{
|
96 |
|
97 |
messages = [
|
98 |
{"role": "system", "content": "You are DailySnap, a highly efficient and intelligent assistant designed to generate infographics using htmnl bootstrap icon and generate highly appealing daily journal as per the user detail"},
|
@@ -205,10 +205,26 @@ def generate_journal_with_images(video_path, frame_interval=30,confidence_thresh
|
|
205 |
|
206 |
def display_journal_with_images(video):
|
207 |
journal_entries, image_paths = generate_journal_with_images(video, frame_interval=30)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
208 |
|
209 |
|
210 |
journal_text = "\n".join(journal_entries)
|
211 |
-
return journal_text, image_paths
|
212 |
|
213 |
|
214 |
with gr.Blocks() as iface:
|
@@ -216,7 +232,8 @@ with gr.Blocks() as iface:
|
|
216 |
journal_output = gr.Textbox(label="Generated Daily Journal", lines=10)
|
217 |
image_gallery = gr.Gallery(label="Annotated Frames")
|
218 |
run_button = gr.Button("Generate Journal")
|
|
|
219 |
|
220 |
-
run_button.click(fn=display_journal_with_images, inputs=video_input, outputs=[journal_output, image_gallery])
|
221 |
|
222 |
iface.launch()
|
|
|
70 |
|
71 |
|
72 |
@spaces.GPU
|
73 |
+
def generate_image_desc(image):
|
74 |
messages = [
|
75 |
{"role": "user", "content": [
|
76 |
{"type": "image"},
|
|
|
91 |
return html_output
|
92 |
|
93 |
@spaces.GPU
|
94 |
+
def generate_journal_infographics(journal):
|
95 |
+
prompt = f"Generate daily journal inforgraphics using html for the following:\n\n{journal}"
|
96 |
|
97 |
messages = [
|
98 |
{"role": "system", "content": "You are DailySnap, a highly efficient and intelligent assistant designed to generate infographics using htmnl bootstrap icon and generate highly appealing daily journal as per the user detail"},
|
|
|
205 |
|
206 |
def display_journal_with_images(video):
|
207 |
journal_entries, image_paths = generate_journal_with_images(video, frame_interval=30)
|
208 |
+
pil_images = []
|
209 |
+
for image_path in image_paths:
|
210 |
+
# Read the image using OpenCV
|
211 |
+
image = cv2.imread(image_path)
|
212 |
+
# Convert the image from BGR (OpenCV) to RGB (PIL)
|
213 |
+
image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
214 |
+
# Convert the NumPy array to a PIL image
|
215 |
+
pil_image = Image.fromarray(image_rgb)
|
216 |
+
pil_images.append(pil_image)
|
217 |
+
|
218 |
+
infograhic_html=''
|
219 |
+
|
220 |
+
if len(pil_images) >= 2: #just for mockup
|
221 |
+
first_frame_detail=generate_image_desc(pil_images[0])
|
222 |
+
second_frame_detail=generate_image_desc(pil_images[0])
|
223 |
+
infograhic_html=generate_journal_infographics(first_frame_detail + "\n\n" + second_frame_detail)
|
224 |
|
225 |
|
226 |
journal_text = "\n".join(journal_entries)
|
227 |
+
return journal_text, image_paths,infograhic_html
|
228 |
|
229 |
|
230 |
with gr.Blocks() as iface:
|
|
|
232 |
journal_output = gr.Textbox(label="Generated Daily Journal", lines=10)
|
233 |
image_gallery = gr.Gallery(label="Annotated Frames")
|
234 |
run_button = gr.Button("Generate Journal")
|
235 |
+
infographic_html=gr.HTML()
|
236 |
|
237 |
+
run_button.click(fn=display_journal_with_images, inputs=video_input, outputs=[journal_output, image_gallery,infographic_html])
|
238 |
|
239 |
iface.launch()
|