Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers.utils import logging
|
2 |
+
logging.set_verbosity_error()
|
3 |
+
|
4 |
+
import warnings
|
5 |
+
warnings.filterwarnings("ignore",
|
6 |
+
message="Using the model-agnostic default `max_length`")
|
7 |
+
|
8 |
+
import os
|
9 |
+
import gradio as gr
|
10 |
+
from transformers import pipeline
|
11 |
+
|
12 |
+
pipe = pipeline("image-to-text",
|
13 |
+
model="Salesforce/blip-image-captioning-base")
|
14 |
+
|
15 |
+
def launch(input):
|
16 |
+
out = pipe(input)
|
17 |
+
return out[0]['generated_text']
|
18 |
+
|
19 |
+
iface = gr.Interface(launch,
|
20 |
+
inputs=gr.Image(type='pil'),
|
21 |
+
outputs="text")
|
22 |
+
|
23 |
+
iface.launch(share=True)
|
24 |
+
# iface.launch(share=True,
|
25 |
+
# server_port=int(os.environ['PORT1']))
|
26 |
+
|
27 |
+
iface.close()
|