daliavanilla commited on
Commit
e06fe15
·
verified ·
1 Parent(s): 3534439

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -0
app.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from PIL import Image
3
+ processor = AutoProcessor.from_pretrained(daliavanilla/BLIP-Radiology-model)
4
+ model = BlipForConditionalGeneration.from_pretrained(daliavanilla/BLIP-Radiology-model)
5
+
6
+ # Define the prediction function
7
+ def generate_caption(image):
8
+ # Process the image
9
+ image = Image.fromarray(image)
10
+ #inputs = tokenizer(image, return_tensors="pt")
11
+ inputs = processor(images=image, return_tensors="pt")#.to(device)
12
+ pixel_values = inputs.pixel_values
13
+
14
+ # Generate caption
15
+ generated_ids = model.generate(pixel_values=pixel_values, max_length=50)
16
+ generated_caption = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
17
+
18
+ return generated_caption
19
+
20
+ # Define the Gradio interface
21
+ interface = gr.Interface(
22
+ fn=generate_caption,
23
+ inputs=gr.Image(),
24
+ outputs=gr.Textbox(),
25
+ live=True
26
+ )
27
+
28
+ # Launch the Gradio interface
29
+ interface.launch()