Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,5 @@
|
|
1 |
from transformers import BlipProcessor, BlipForConditionalGeneration
|
2 |
from PIL import Image
|
3 |
-
import pandas as pd
|
4 |
-
import numpy as np
|
5 |
import gradio as gr
|
6 |
import tempfile
|
7 |
import os
|
@@ -41,7 +39,6 @@ def generate_keywords(caption):
|
|
41 |
Returns:
|
42 |
list: A list of single-word keywords.
|
43 |
"""
|
44 |
-
# Example simple keyword extraction (use a more sophisticated method if needed)
|
45 |
words = caption.split()
|
46 |
keywords = list(set(words))[:50] # Take unique words and limit to 50
|
47 |
return keywords
|
@@ -65,7 +62,6 @@ def process_images(image_files):
|
|
65 |
caption = generate_image_caption(image)
|
66 |
if caption:
|
67 |
keywords = generate_keywords(caption)
|
68 |
-
# Ensure the title is within the 70 to 100 characters range
|
69 |
title = caption if 70 <= len(caption) <= 100 else caption[:100]
|
70 |
metadata.append({
|
71 |
'filename': filename,
|
@@ -84,13 +80,13 @@ def process_images(image_files):
|
|
84 |
keywords = ','.join(data['keywords'])
|
85 |
writer.writerow([filename, title, keywords])
|
86 |
|
87 |
-
return [Image.open(
|
88 |
|
89 |
# Define Gradio interface
|
90 |
iface = gr.Interface(
|
91 |
fn=process_images,
|
92 |
inputs=[
|
93 |
-
gr.
|
94 |
],
|
95 |
outputs=[
|
96 |
gr.Gallery(label="Processed Images"),
|
|
|
1 |
from transformers import BlipProcessor, BlipForConditionalGeneration
|
2 |
from PIL import Image
|
|
|
|
|
3 |
import gradio as gr
|
4 |
import tempfile
|
5 |
import os
|
|
|
39 |
Returns:
|
40 |
list: A list of single-word keywords.
|
41 |
"""
|
|
|
42 |
words = caption.split()
|
43 |
keywords = list(set(words))[:50] # Take unique words and limit to 50
|
44 |
return keywords
|
|
|
62 |
caption = generate_image_caption(image)
|
63 |
if caption:
|
64 |
keywords = generate_keywords(caption)
|
|
|
65 |
title = caption if 70 <= len(caption) <= 100 else caption[:100]
|
66 |
metadata.append({
|
67 |
'filename': filename,
|
|
|
80 |
keywords = ','.join(data['keywords'])
|
81 |
writer.writerow([filename, title, keywords])
|
82 |
|
83 |
+
return [Image.open(image_file.name) for image_file in image_files], csv_file_path
|
84 |
|
85 |
# Define Gradio interface
|
86 |
iface = gr.Interface(
|
87 |
fn=process_images,
|
88 |
inputs=[
|
89 |
+
gr.File(label="Upload Image Files", type="file", multiple=True)
|
90 |
],
|
91 |
outputs=[
|
92 |
gr.Gallery(label="Processed Images"),
|