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