zamal commited on
Commit
093f79d
·
verified ·
1 Parent(s): 2db9098

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -10
app.py CHANGED
@@ -1,15 +1,12 @@
1
  import gradio as gr
2
  from transformers import AutoModelForCausalLM, AutoProcessor, GenerationConfig
3
  from PIL import Image
 
 
4
 
5
  # Load the model and processor
6
  repo_name = "cyan2k/molmo-7B-O-bnb-4bit"
7
- arguments = {
8
- "device_map": "auto",
9
- "torch_dtype": "auto",
10
- "trust_remote_code": True,
11
- "load_in_8bit": True # Use 8-bit for reduced memory footprint
12
- }
13
 
14
  # Load the processor and model
15
  processor = AutoProcessor.from_pretrained(repo_name, **arguments)
@@ -19,12 +16,12 @@ def describe_image(image):
19
  # Process the uploaded image
20
  inputs = processor.process(
21
  images=[image],
22
- text="Describe this image in great detail."
23
  )
24
 
25
  # Move inputs to model device
26
- inputs = {k: v.to(model.device) for k, v in inputs.items()} # Removed unsqueeze(0) to keep batch size
27
-
28
  # Generate output
29
  output = model.generate_from_batch(
30
  inputs,
@@ -57,4 +54,4 @@ def gradio_app():
57
  interface.launch()
58
 
59
  # Launch the Gradio app
60
- gradio_app()
 
1
  import gradio as gr
2
  from transformers import AutoModelForCausalLM, AutoProcessor, GenerationConfig
3
  from PIL import Image
4
+ import requests
5
+ from io import BytesIO
6
 
7
  # Load the model and processor
8
  repo_name = "cyan2k/molmo-7B-O-bnb-4bit"
9
+ arguments = {"device_map": "auto", "torch_dtype": "auto", "trust_remote_code": True}
 
 
 
 
 
10
 
11
  # Load the processor and model
12
  processor = AutoProcessor.from_pretrained(repo_name, **arguments)
 
16
  # Process the uploaded image
17
  inputs = processor.process(
18
  images=[image],
19
+ text="Describe this image."
20
  )
21
 
22
  # Move inputs to model device
23
+ inputs = {k: v.to(model.device).unsqueeze(0) for k, v in inputs.items()}
24
+
25
  # Generate output
26
  output = model.generate_from_batch(
27
  inputs,
 
54
  interface.launch()
55
 
56
  # Launch the Gradio app
57
+ gradio_app()