Spaces:
Sleeping
Sleeping
kwabs22
commited on
Commit
•
37f1dd5
1
Parent(s):
032673b
remove unneeded comments
Browse files
app.py
CHANGED
@@ -9,15 +9,7 @@ def clear_model(model):
|
|
9 |
del model
|
10 |
gc.collect()
|
11 |
|
12 |
-
|
13 |
def process_image_and_question(image, question):
|
14 |
-
# Placeholder for your image processing and question answering
|
15 |
-
# Replace this with your actual model processing
|
16 |
-
# For example:
|
17 |
-
# enc_image = model.encode_image(image)
|
18 |
-
# answer = model.answer_question(enc_image, question, tokenizer)
|
19 |
-
# return answer
|
20 |
-
|
21 |
FinalOutput = ""
|
22 |
model_id = "vikhyatk/moondream1"
|
23 |
|
@@ -32,15 +24,13 @@ def process_image_and_question(image, question):
|
|
32 |
model = AutoModelForCausalLM.from_pretrained(model_id, trust_remote_code=True)
|
33 |
tokenizer = Tokenizer.from_pretrained(model_id)
|
34 |
|
35 |
-
# Assuming you have a correct way to process the image
|
36 |
-
#image = Image.open('/content/_57e22ed5-217c-4004-a279-eeecc18cbd55.jpg') #/content/Bard_Generated_Image (3).jpg')
|
37 |
-
# This part of the code is incorrect for a standard transformers model
|
38 |
enc_image = model.encode_image(image)
|
39 |
FinalOutput += model.answer_question(enc_image, "how many people are there? also explain if the image is weird?", tokenizer)
|
40 |
|
41 |
model_size = asizeof.asizeof(model)
|
42 |
tokenizer_size = asizeof.asizeof(tokenizer)
|
43 |
-
FinalOutput += f"\nModel size in RAM: {model_size} bytes, Tokenizer size in RAM: {tokenizer_size} bytes"
|
|
|
44 |
|
45 |
#model load and set-up = 1 min and inference on CPU = 2 min
|
46 |
return FinalOutput
|
@@ -50,7 +40,7 @@ iface = gr.Interface(fn=process_image_and_question,
|
|
50 |
inputs=[gr.Image(type="pil"), gr.Textbox(lines=2, placeholder="Ask a question about the image...")],
|
51 |
outputs="text",
|
52 |
title="Image Question Answering",
|
53 |
-
description="Upload an image and ask a question about it. (
|
54 |
|
55 |
# Launch the interface
|
56 |
iface.launch()
|
|
|
9 |
del model
|
10 |
gc.collect()
|
11 |
|
|
|
12 |
def process_image_and_question(image, question):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
FinalOutput = ""
|
14 |
model_id = "vikhyatk/moondream1"
|
15 |
|
|
|
24 |
model = AutoModelForCausalLM.from_pretrained(model_id, trust_remote_code=True)
|
25 |
tokenizer = Tokenizer.from_pretrained(model_id)
|
26 |
|
|
|
|
|
|
|
27 |
enc_image = model.encode_image(image)
|
28 |
FinalOutput += model.answer_question(enc_image, "how many people are there? also explain if the image is weird?", tokenizer)
|
29 |
|
30 |
model_size = asizeof.asizeof(model)
|
31 |
tokenizer_size = asizeof.asizeof(tokenizer)
|
32 |
+
FinalOutput += f"\n\nExpected Ram usage: +- 9.5 gb \nModel size in RAM: {model_size} bytes, Tokenizer size in RAM: {tokenizer_size} bytes"
|
33 |
+
#clear_model(model) #Not needed due to try except check
|
34 |
|
35 |
#model load and set-up = 1 min and inference on CPU = 2 min
|
36 |
return FinalOutput
|
|
|
40 |
inputs=[gr.Image(type="pil"), gr.Textbox(lines=2, placeholder="Ask a question about the image...")],
|
41 |
outputs="text",
|
42 |
title="Image Question Answering",
|
43 |
+
description="Upload an image and ask a question about it. ( 3 - 4 min response time expected )")
|
44 |
|
45 |
# Launch the interface
|
46 |
iface.launch()
|