Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,29 +1,22 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import BlipProcessor, BlipForConditionalGeneration
|
3 |
-
|
4 |
-
|
5 |
|
6 |
model_id = "dblasko/blip-dalle3-img2prompt"
|
7 |
model = BlipForConditionalGeneration.from_pretrained(model_id)
|
8 |
processor = BlipProcessor.from_pretrained(model_id)
|
9 |
|
10 |
def generate_caption(image):
|
11 |
-
|
12 |
-
|
13 |
|
14 |
-
|
15 |
-
|
16 |
|
17 |
-
|
18 |
-
tts = gTTS(text=generated_caption, lang='en')
|
19 |
-
tts.save("generated_audio.mp3")
|
20 |
|
21 |
-
return generated_caption, "generated_audio.mp3"
|
22 |
|
23 |
-
def play_audio(audio_path):
|
24 |
-
# Display an audio player
|
25 |
-
return ipd.Audio(audio_path)
|
26 |
|
27 |
-
# Create a Gradio interface with an image input
|
28 |
-
demo = gr.Interface(fn=generate_caption, inputs=gr.Image(), outputs=
|
29 |
-
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import BlipProcessor, BlipForConditionalGeneration
|
3 |
+
|
4 |
+
|
5 |
|
6 |
model_id = "dblasko/blip-dalle3-img2prompt"
|
7 |
model = BlipForConditionalGeneration.from_pretrained(model_id)
|
8 |
processor = BlipProcessor.from_pretrained(model_id)
|
9 |
|
10 |
def generate_caption(image):
|
11 |
+
inputs = processor(images=image, return_tensors="pt")
|
12 |
+
pixel_values = inputs.pixel_values
|
13 |
|
14 |
+
generated_ids = model.generate(pixel_values=pixel_values, max_length=50)
|
15 |
+
generated_caption = processor.batch_decode(generated_ids, skip_special_tokens=True, temperature=0.8, top_k=40, top_p=0.9)[0]
|
16 |
|
17 |
+
return generated_caption
|
|
|
|
|
18 |
|
|
|
19 |
|
|
|
|
|
|
|
20 |
|
21 |
+
# Create a Gradio interface with an image input and a textbox output
|
22 |
+
demo = gr.Interface(fn=generate_caption, inputs=gr.Image(), outputs=gr.Textbox(label="Generated caption"))
|
|