arshi229 commited on
Commit
09f9de9
·
verified ·
1 Parent(s): c2c9025

Create api.py

Browse files
Files changed (1) hide show
  1. api.py +23 -0
api.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ !pip install transformers
2
+ !pip install gradio
3
+ !pip install gradio_client
4
+ !pip install -U gradio_client
5
+ from transformers.utils import logging
6
+ logging.set_verbosity_error()
7
+
8
+ import warnings
9
+ warnings.filterwarnings("ignore",
10
+ message="Using the model-agnostic default `max_length`")
11
+ import os
12
+ !pip install gradio_client==1.14.0
13
+ import gradio as gr
14
+ from transformers import pipeline
15
+ pipe = pipeline("image-to-text",
16
+ model="Salesforce/blip-image-captioning-base")
17
+ def launch(input):
18
+ out = pipe(input)
19
+ return out[0]['generated_text']
20
+ iface = gr.Interface(launch,
21
+ inputs=gr.Image(type='pil'),
22
+ outputs="text")
23
+ iface.launch()