Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -20,6 +20,7 @@ import fitz
|
|
20 |
|
21 |
from transformers import (
|
22 |
Qwen2_5_VLForConditionalGeneration,
|
|
|
23 |
AutoModelForVision2Seq,
|
24 |
AutoModelForImageTextToText,
|
25 |
AutoModel,
|
@@ -77,12 +78,17 @@ model_g = Qwen2_5_VLForConditionalGeneration.from_pretrained(
|
|
77 |
MODEL_ID_G, trust_remote_code=True, subfolder=SUBFOLDER, torch_dtype=torch.float16
|
78 |
).to(device).eval()
|
79 |
|
80 |
-
MODEL_ID_I = "
|
81 |
processor_i = AutoProcessor.from_pretrained(MODEL_ID_I, trust_remote_code=True)
|
82 |
-
model_i =
|
83 |
MODEL_ID_I, trust_remote_code=True, torch_dtype=torch.float16, _attn_implementation="flash_attention_2"
|
84 |
).to(device).eval()
|
85 |
|
|
|
|
|
|
|
|
|
|
|
86 |
|
87 |
# --- PDF Generation and Preview Utility Function ---
|
88 |
def generate_and_preview_pdf(image: Image.Image, text_content: str, font_size: int, line_spacing: float, alignment: str, image_size: str):
|
@@ -178,7 +184,8 @@ def process_document_stream(
|
|
178 |
elif model_name == "LFM2-VL-1.6B": processor, model = processor_t, model_t
|
179 |
elif model_name == "SmolVLM-Instruct-250M": processor, model = processor_c, model_c
|
180 |
elif model_name == "MonkeyOCR-pro-1.2B": processor, model = processor_g, model_g
|
181 |
-
elif model_name == "
|
|
|
182 |
else:
|
183 |
yield "Invalid model selected.", ""
|
184 |
return
|
@@ -235,7 +242,7 @@ def create_gradio_interface():
|
|
235 |
# Left Column (Inputs)
|
236 |
with gr.Column(scale=1):
|
237 |
model_choice = gr.Dropdown(
|
238 |
-
choices=["LFM2-VL-1.6B", "LFM2-VL-450M", "SmolVLM-Instruct-250M", "
|
239 |
label="Select Model", value="LFM2-VL-1.6B"
|
240 |
)
|
241 |
prompt_input = gr.Textbox(label="Query Input", placeholder="✦︎ Enter your query")
|
|
|
20 |
|
21 |
from transformers import (
|
22 |
Qwen2_5_VLForConditionalGeneration,
|
23 |
+
AutoModelForCausalLM,
|
24 |
AutoModelForVision2Seq,
|
25 |
AutoModelForImageTextToText,
|
26 |
AutoModel,
|
|
|
78 |
MODEL_ID_G, trust_remote_code=True, subfolder=SUBFOLDER, torch_dtype=torch.float16
|
79 |
).to(device).eval()
|
80 |
|
81 |
+
MODEL_ID_I = "microsoft/Florence-2-large"
|
82 |
processor_i = AutoProcessor.from_pretrained(MODEL_ID_I, trust_remote_code=True)
|
83 |
+
model_i = AutoModelForCausalLM.from_pretrained(
|
84 |
MODEL_ID_I, trust_remote_code=True, torch_dtype=torch.float16, _attn_implementation="flash_attention_2"
|
85 |
).to(device).eval()
|
86 |
|
87 |
+
MODEL_ID_A = "microsoft/Florence-2-base"
|
88 |
+
processor_a = AutoProcessor.from_pretrained(MODEL_ID_A, trust_remote_code=True)
|
89 |
+
model_a = AutoModelForCausalLM.from_pretrained(
|
90 |
+
MODEL_ID_A, trust_remote_code=True, torch_dtype=torch.float16, _attn_implementation="flash_attention_2"
|
91 |
+
).to(device).eval()
|
92 |
|
93 |
# --- PDF Generation and Preview Utility Function ---
|
94 |
def generate_and_preview_pdf(image: Image.Image, text_content: str, font_size: int, line_spacing: float, alignment: str, image_size: str):
|
|
|
184 |
elif model_name == "LFM2-VL-1.6B": processor, model = processor_t, model_t
|
185 |
elif model_name == "SmolVLM-Instruct-250M": processor, model = processor_c, model_c
|
186 |
elif model_name == "MonkeyOCR-pro-1.2B": processor, model = processor_g, model_g
|
187 |
+
elif model_name == "Florence-2-large": processor, model = processor_i, model_i
|
188 |
+
elif model_name == "Florence-2-base": processor, model = processor_a, model_a
|
189 |
else:
|
190 |
yield "Invalid model selected.", ""
|
191 |
return
|
|
|
242 |
# Left Column (Inputs)
|
243 |
with gr.Column(scale=1):
|
244 |
model_choice = gr.Dropdown(
|
245 |
+
choices=["LFM2-VL-1.6B", "LFM2-VL-450M", "SmolVLM-Instruct-250M", "Florence-2-large", "MonkeyOCR-pro-1.2B", "Florence-2-base"],
|
246 |
label="Select Model", value="LFM2-VL-1.6B"
|
247 |
)
|
248 |
prompt_input = gr.Textbox(label="Query Input", placeholder="✦︎ Enter your query")
|