Walid-Ahmed commited on
Commit
027c75c
·
verified ·
1 Parent(s): 7e0c205

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -27
app.py CHANGED
@@ -2,31 +2,6 @@ import gradio as gr
2
  import torch
3
  from transformers import BlipForQuestionAnswering, AutoProcessor
4
  from PIL import Image
5
- import spaces
6
-
7
- # Check device
8
- device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
9
-
10
- # Load model and processor
11
- model = BlipForQuestionAnswering.from_pretrained("Salesforce/blip-vqa-base").to(device)
12
- processor = AutoProcessor.from_pretrained("Salesforce/blip-vqa-base")
13
-
14
- @spaces.GPU # ZeroGPU: Allocate GPU only when generating images
15
- def answer_question(image, question):
16
- inputs = processor(image, question, return_tensors="pt").to(device)
17
- out = model.generate(**inputs)
18
- return processor.decode(out[0], skip_special_tokens=True)
19
-
20
- iface = gr.Interface(
21
- fn=answer_question,
22
- inputs=[gr.Image(type="pil"), gr.Textbox(placeholder="Enter your question")],
23
- outputs=gr.Textbox(label="Answer"),
24
- title="Visual Question Answering with BLIP",
25
- description="Upload an image and ask a question about its content.",
26
- import gradio as gr
27
- import torch
28
- from transformers import BlipForQuestionAnswering, AutoProcessor
29
- from PIL import Image
30
 
31
  # Check device
32
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
@@ -50,5 +25,3 @@ iface = gr.Interface(
50
  )
51
 
52
  iface.launch()
53
-
54
-
 
2
  import torch
3
  from transformers import BlipForQuestionAnswering, AutoProcessor
4
  from PIL import Image
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
  # Check device
7
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
 
25
  )
26
 
27
  iface.launch()