Spaces:
Sleeping
Sleeping
Create app.py
Browse filesInitial commit
app.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import warnings
|
3 |
+
import gradio as gr
|
4 |
+
from transformers import pipeline
|
5 |
+
from transformers.utils import logging
|
6 |
+
|
7 |
+
# Ignore warning that are not application related
|
8 |
+
logging.set_verbosity_error()
|
9 |
+
warnings.filterwarnings("ignore",category=FutureWarning)
|
10 |
+
warnings.filterwarnings("ignore", message="Using the model-agnostic default `max_length`")
|
11 |
+
|
12 |
+
# Load model
|
13 |
+
image_captioning = pipeline("image-to-text", model="Salesforce/blip-image-captioning-base")
|
14 |
+
|
15 |
+
# Perform inference
|
16 |
+
def launch(input):
|
17 |
+
out= image_captioning(input)
|
18 |
+
return out[0]['generated_text']
|
19 |
+
|
20 |
+
# Create the gradio interface
|
21 |
+
int_face = gr.Interface(
|
22 |
+
launch,
|
23 |
+
inputs=gr.Image(type="pil"),
|
24 |
+
outputs="text"
|
25 |
+
)
|
26 |
+
|
27 |
+
# Run the gradio interface
|
28 |
+
int_face.launch()
|