m7mdal7aj commited on
Commit
faaa7b5
1 Parent(s): 46f4aef

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -55
app.py DELETED
@@ -1,55 +0,0 @@
1
- import streamlit as st
2
- import torch
3
-
4
- from transformers import Blip2Processor, Blip2ForConditionalGeneration
5
-
6
-
7
- def load_caption_model():
8
- # Quantization Config
9
- bnb_config = BitsAndBytesConfig(
10
- load_in_8bit=True,
11
- bnb_8bit_quant_type="nf4",
12
- bnb_8bit_compute_dtype=torch.float16,
13
- bnb_8bit_use_double_quant=False
14
- )
15
-
16
-
17
-
18
-
19
- processor = Blip2Processor.from_pretrained("Salesforce/blip2-opt-2.7b")
20
- model = Blip2ForConditionalGeneration.from_pretrained("Salesforce/blip2-opt-2.7b", load_in_8bit=True,torch_dtype=torch.float16, device_map="auto")
21
-
22
- return, model, processor
23
-
24
-
25
-
26
- def answer_question(image, question, model, processor):
27
-
28
-
29
- image = Image.open(image).convert('RGB')
30
-
31
- inputs = processor(image, question, return_tensors="pt").to("cuda", torch.float16)
32
-
33
- out = model.generate(**inputs, max_length=200, min_length=20, num_beams=1)
34
-
35
- answer = processor.decode(out[0], skip_special_tokens=True).strip()
36
- return answer
37
-
38
- st.title("Image Question Answering")
39
-
40
- # File uploader for the image
41
- image = st.file_uploader("Upload an image", type=["png", "jpg", "jpeg"])
42
-
43
- # Text input for the question
44
- question = st.text_input("Enter your question about the image:")
45
-
46
- if st.button("Get Answer"):
47
- if image is not None and question:
48
- # Display the image
49
- st.image(image, use_column_width=True)
50
- # Get and display the answer
51
- model, processor = load_caption_model()
52
- answer = answer_question(image, question, model, processor)
53
- st.write(answer)
54
- else:
55
- st.write("Please upload an image and enter a question.")