Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,32 +1,27 @@
|
|
1 |
-
import
|
2 |
-
from PIL import Image
|
3 |
-
from PIL import Image, ImageDraw
|
4 |
-
from image_whisper_helper import summarize_predictions_natural_language, render_results_in_image
|
5 |
from transformers import pipeline
|
6 |
-
from tokenizers import Tokenizer, Encoding
|
7 |
-
from tokenizers import decoders
|
8 |
-
from tokenizers import models
|
9 |
-
from tokenizers import normalizers
|
10 |
-
from tokenizers import pre_tokenizers
|
11 |
-
from tokenizers import processors
|
12 |
-
import io
|
13 |
-
import matplotlib.pyplot as plt
|
14 |
-
import requests
|
15 |
-
import inflect
|
16 |
-
from PIL import Image
|
17 |
-
from predictions import get_predictions # Replace 'your_module' with the name of the module where your function is defined
|
18 |
|
19 |
-
|
20 |
-
|
|
|
|
|
|
|
21 |
|
22 |
-
|
|
|
|
|
|
|
|
|
23 |
|
24 |
-
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
|
27 |
-
|
28 |
-
|
29 |
-
st.audio(audio, format='audio/wav')
|
30 |
-
|
31 |
-
if __name__ == '__main__':
|
32 |
-
main()
|
|
|
1 |
+
import gradio as gr
|
|
|
|
|
|
|
2 |
from transformers import pipeline
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
+
# Load the image-to-text pipeline
|
5 |
+
image_to_text_pipelines = {
|
6 |
+
"Salesforce/blip-image-captioning-base": pipeline("image-to-text", model="Salesforce/blip-image-captioning-base"),
|
7 |
+
# Add more models if needed
|
8 |
+
}
|
9 |
|
10 |
+
def generate_caption(input_image, model_name="Salesforce/blip-image-captioning-base"):
|
11 |
+
# Generate caption for the input image using the selected model
|
12 |
+
image_to_text_pipeline = image_to_text_pipelines[model_name]
|
13 |
+
caption = image_to_text_pipeline(input_image)[0]['generated_text']
|
14 |
+
return caption
|
15 |
|
16 |
+
# Interface for launching the model
|
17 |
+
interface = gr.Interface(
|
18 |
+
fn=generate_caption,
|
19 |
+
inputs=gr.Image(type='pil', label="Input Image"),
|
20 |
+
outputs="text",
|
21 |
+
title="Image Captioning Model",
|
22 |
+
description="This model generates captions for images.",
|
23 |
+
theme="default",
|
24 |
+
)
|
25 |
|
26 |
+
# Launch the interface
|
27 |
+
interface.launch()
|
|
|
|
|
|
|
|