Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,33 +5,38 @@ from PIL import Image, ImageDraw, ImageFont
|
|
| 5 |
import json
|
| 6 |
import re
|
| 7 |
from spaces import GPU
|
|
|
|
| 8 |
|
| 9 |
# --- 1. Configurations and Constants ---
|
| 10 |
# Define user-facing names and Hugging Face IDs for the models
|
| 11 |
MODEL_BASE_NAME = "Latex2Layout-Base"
|
| 12 |
MODEL_BASE_ID = "ChaseHan/Latex2Layout-2000-sync"
|
| 13 |
|
| 14 |
-
MODEL_ENHANCED_NAME = "
|
| 15 |
-
|
|
|
|
|
|
|
| 16 |
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
# Target image size for model input
|
| 20 |
TARGET_SIZE = (924, 1204)
|
| 21 |
|
| 22 |
# Visualization Style Constants
|
| 23 |
OUTLINE_WIDTH = 3
|
| 24 |
-
# Color mapping for different layout regions (RGBA for transparency)
|
| 25 |
LABEL_COLORS = {
|
| 26 |
-
"title": (255, 82, 82, 90),
|
| 27 |
"abstract": (46, 204, 113, 90), # Green
|
| 28 |
"heading": (52, 152, 219, 90), # Blue
|
| 29 |
"footnote": (241, 196, 15, 90), # Yellow
|
| 30 |
"figure": (155, 89, 182, 90), # Purple
|
| 31 |
"figure caption": (26, 188, 156, 90),# Teal
|
| 32 |
-
"table": (230, 126, 34, 90),
|
| 33 |
-
"table caption": (44, 62, 80, 90),
|
| 34 |
-
"math": (231, 76, 60, 90),
|
| 35 |
"text": (149, 165, 166, 90), # Gray
|
| 36 |
"other": (127, 140, 141, 90) # Light Gray
|
| 37 |
}
|
|
@@ -43,71 +48,149 @@ DEFAULT_PROMPT = (
|
|
| 43 |
# --- 2. Load Models and Processor ---
|
| 44 |
print("Loading models, this will take some time and VRAM...")
|
| 45 |
try:
|
| 46 |
-
#
|
| 47 |
-
print(f"Loading {MODEL_BASE_NAME}...")
|
| 48 |
model_base = Qwen2_5_VLForConditionalGeneration.from_pretrained(
|
| 49 |
MODEL_BASE_ID,
|
| 50 |
torch_dtype=torch.float16,
|
| 51 |
device_map="auto"
|
| 52 |
)
|
| 53 |
|
| 54 |
-
|
|
|
|
|
|
|
| 55 |
model_enhanced = Qwen2_5_VLForConditionalGeneration.from_pretrained(
|
| 56 |
-
|
| 57 |
-
torch_dtype=torch.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
device_map="auto"
|
| 59 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
|
|
|
|
| 61 |
processor = AutoProcessor.from_pretrained(MODEL_BASE_ID)
|
| 62 |
-
print("All models loaded successfully!")
|
| 63 |
except Exception as e:
|
| 64 |
print(f"Error loading models: {e}")
|
| 65 |
exit()
|
| 66 |
|
| 67 |
-
# --- 3. Core Inference and Visualization
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
@GPU
|
| 69 |
def analyze_and_visualize_layout(input_image: Image.Image, selected_model_name: str, prompt: str, use_greedy: bool, temperature: float, top_p: float, progress=gr.Progress(track_tqdm=True)):
|
| 70 |
"""
|
| 71 |
Takes an image and model parameters, runs inference, and returns a visualized image and raw text output.
|
|
|
|
| 72 |
"""
|
| 73 |
if input_image is None:
|
| 74 |
return None, "Please upload an image first."
|
| 75 |
|
| 76 |
-
|
| 77 |
-
model = model_base if selected_model_name == MODEL_BASE_NAME else model_enhanced
|
| 78 |
-
|
| 79 |
-
progress(0, desc=f"Resizing image for {selected_model_name}...")
|
| 80 |
image = input_image.resize(TARGET_SIZE).convert("RGBA")
|
| 81 |
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
|
|
|
|
|
|
|
| 111 |
overlay = Image.new('RGBA', image.size, (255, 255, 255, 0))
|
| 112 |
draw = ImageDraw.Draw(overlay)
|
| 113 |
|
|
@@ -117,7 +200,9 @@ def analyze_and_visualize_layout(input_image: Image.Image, selected_model_name:
|
|
| 117 |
font = ImageFont.load_default()
|
| 118 |
|
| 119 |
for item in sorted(results, key=lambda x: x.get("order", 999)):
|
| 120 |
-
bbox
|
|
|
|
|
|
|
| 121 |
if not bbox or len(bbox) != 4: continue
|
| 122 |
|
| 123 |
fill_color_rgba = LABEL_COLORS.get(label, LABEL_COLORS["other"])
|
|
@@ -139,12 +224,12 @@ def clear_outputs():
|
|
| 139 |
def toggle_sampling_params(use_greedy):
|
| 140 |
"""Updates visibility of temperature and top-p sliders."""
|
| 141 |
is_visible = not use_greedy
|
| 142 |
-
return gr.update(visible=is_visible)
|
| 143 |
|
| 144 |
# --- 4. Gradio User Interface ---
|
| 145 |
with gr.Blocks(theme=gr.themes.Glass(), title="Academic Paper Layout Detection") as demo:
|
| 146 |
gr.Markdown("# 📄 Academic Paper Layout Detection")
|
| 147 |
-
gr.Markdown("Welcome! This tool uses
|
| 148 |
gr.Markdown("<hr>")
|
| 149 |
|
| 150 |
with gr.Row():
|
|
@@ -154,22 +239,23 @@ with gr.Blocks(theme=gr.themes.Glass(), title="Academic Paper Layout Detection")
|
|
| 154 |
output_image = gr.Image(type="pil", label="Analyzed Layout", interactive=False, height=700)
|
| 155 |
|
| 156 |
with gr.Row():
|
| 157 |
-
|
| 158 |
|
| 159 |
with gr.Accordion("Advanced Settings", open=False):
|
| 160 |
-
model_selector = gr.Radio(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 161 |
prompt_textbox = gr.Textbox(label="Prompt", value=DEFAULT_PROMPT, lines=5)
|
| 162 |
|
| 163 |
-
# NEW: Checkbox to toggle between greedy and sampling
|
| 164 |
greedy_checkbox = gr.Checkbox(label="Use Greedy Decoding", value=True, info="Faster and deterministic. Uncheck to enable Temperature and Top-p.")
|
| 165 |
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
temp_slider = gr.Slider(minimum=0.0, maximum=2.0, step=0.05, value=0.7, label="Temperature")
|
| 169 |
-
top_p_slider = gr.Slider(minimum=0.0, maximum=1.0, step=0.05, value=0.9, label="Top-p")
|
| 170 |
|
| 171 |
-
output_text = gr.Textbox(label="Model Raw Output", lines=
|
| 172 |
-
gr.Examples(examples=[["1.png"], ["2.png"], ["
|
| 173 |
gr.Markdown("<p style='text-align:center; color:grey;'>Powered by the Latex2Layout dataset by Feijiang Han</p>")
|
| 174 |
|
| 175 |
# --- Event Handlers ---
|
|
@@ -182,7 +268,6 @@ with gr.Blocks(theme=gr.themes.Glass(), title="Academic Paper Layout Detection")
|
|
| 182 |
input_image.upload(fn=clear_outputs, inputs=None, outputs=[output_image, output_text])
|
| 183 |
input_image.clear(fn=clear_outputs, inputs=None, outputs=[output_image, output_text])
|
| 184 |
|
| 185 |
-
# NEW: Event handler to show/hide sliders
|
| 186 |
greedy_checkbox.change(
|
| 187 |
fn=toggle_sampling_params,
|
| 188 |
inputs=greedy_checkbox,
|
|
|
|
| 5 |
import json
|
| 6 |
import re
|
| 7 |
from spaces import GPU
|
| 8 |
+
from peft import PeftModel
|
| 9 |
|
| 10 |
# --- 1. Configurations and Constants ---
|
| 11 |
# Define user-facing names and Hugging Face IDs for the models
|
| 12 |
MODEL_BASE_NAME = "Latex2Layout-Base"
|
| 13 |
MODEL_BASE_ID = "ChaseHan/Latex2Layout-2000-sync"
|
| 14 |
|
| 15 |
+
MODEL_ENHANCED_NAME = "Qwen2.5-VL + GRPO LoRA (Merged)"
|
| 16 |
+
MODEL_ENHANCED_BASE_ID = "ZelongWang/Qwen2.5-VL-3B-Instruct-DocOD-2"
|
| 17 |
+
MODEL_ENHANCED_LORA_ID = "ZelongWang/Qwen2.5-VL-3B-GRPO-lora-pdf-v3"
|
| 18 |
+
LORA_CHECKPOINT_FOLDER = "checkpoint-525" # Subfolder containing the adapter
|
| 19 |
|
| 20 |
+
# --- NEW: Add a name for the Mixing mode ---
|
| 21 |
+
MODEL_MIXING_NAME = "Mixing (Base + Enhanced)"
|
| 22 |
+
|
| 23 |
+
MODEL_CHOICES = [MODEL_BASE_NAME, MODEL_ENHANCED_NAME, MODEL_MIXING_NAME]
|
| 24 |
|
| 25 |
# Target image size for model input
|
| 26 |
TARGET_SIZE = (924, 1204)
|
| 27 |
|
| 28 |
# Visualization Style Constants
|
| 29 |
OUTLINE_WIDTH = 3
|
|
|
|
| 30 |
LABEL_COLORS = {
|
| 31 |
+
"title": (255, 82, 82, 90), # Red
|
| 32 |
"abstract": (46, 204, 113, 90), # Green
|
| 33 |
"heading": (52, 152, 219, 90), # Blue
|
| 34 |
"footnote": (241, 196, 15, 90), # Yellow
|
| 35 |
"figure": (155, 89, 182, 90), # Purple
|
| 36 |
"figure caption": (26, 188, 156, 90),# Teal
|
| 37 |
+
"table": (230, 126, 34, 90), # Orange
|
| 38 |
+
"table caption": (44, 62, 80, 90), # Dark Blue/Gray
|
| 39 |
+
"math": (231, 76, 60, 90), # Pomegranate
|
| 40 |
"text": (149, 165, 166, 90), # Gray
|
| 41 |
"other": (127, 140, 141, 90) # Light Gray
|
| 42 |
}
|
|
|
|
| 48 |
# --- 2. Load Models and Processor ---
|
| 49 |
print("Loading models, this will take some time and VRAM...")
|
| 50 |
try:
|
| 51 |
+
# Load the original base model
|
| 52 |
+
print(f"Loading base model: {MODEL_BASE_NAME}...")
|
| 53 |
model_base = Qwen2_5_VLForConditionalGeneration.from_pretrained(
|
| 54 |
MODEL_BASE_ID,
|
| 55 |
torch_dtype=torch.float16,
|
| 56 |
device_map="auto"
|
| 57 |
)
|
| 58 |
|
| 59 |
+
# Load and merge the new enhanced model directly from the Hub
|
| 60 |
+
print(f"Loading enhanced model base: {MODEL_ENHANCED_BASE_ID}...")
|
| 61 |
+
# Step 1: Load the new base model
|
| 62 |
model_enhanced = Qwen2_5_VLForConditionalGeneration.from_pretrained(
|
| 63 |
+
MODEL_ENHANCED_BASE_ID,
|
| 64 |
+
torch_dtype=torch.bfloat16,
|
| 65 |
+
device_map="auto",
|
| 66 |
+
)
|
| 67 |
+
|
| 68 |
+
print(f"Loading LoRA adapter online from: {MODEL_ENHANCED_LORA_ID}...")
|
| 69 |
+
# Step 2: Load Peft adapter directly from the Hub, specifying the subfolder
|
| 70 |
+
model_enhanced = PeftModel.from_pretrained(
|
| 71 |
+
model_enhanced,
|
| 72 |
+
MODEL_ENHANCED_LORA_ID,
|
| 73 |
+
subfolder=LORA_CHECKPOINT_FOLDER,
|
| 74 |
device_map="auto"
|
| 75 |
)
|
| 76 |
+
|
| 77 |
+
# Step 3: Merge the adapter weights and unload the PeftModel
|
| 78 |
+
print("Merging LoRA adapter...")
|
| 79 |
+
model_enhanced = model_enhanced.merge_and_unload()
|
| 80 |
+
print(f"Successfully loaded and merged model: {MODEL_ENHANCED_NAME}")
|
| 81 |
|
| 82 |
+
# Load processor
|
| 83 |
processor = AutoProcessor.from_pretrained(MODEL_BASE_ID)
|
| 84 |
+
print("All models and processor loaded successfully!")
|
| 85 |
except Exception as e:
|
| 86 |
print(f"Error loading models: {e}")
|
| 87 |
exit()
|
| 88 |
|
| 89 |
+
# --- 3. Core Inference, Merging, and Visualization ---
|
| 90 |
+
|
| 91 |
+
def calculate_iou(boxA, boxB):
|
| 92 |
+
"""Calculate Intersection over Union (IoU) of two bounding boxes."""
|
| 93 |
+
# Determine the coordinates of the intersection rectangle
|
| 94 |
+
xA = max(boxA[0], boxB[0])
|
| 95 |
+
yA = max(boxA[1], boxB[1])
|
| 96 |
+
xB = min(boxA[2], boxB[2])
|
| 97 |
+
yB = min(boxA[3], boxB[3])
|
| 98 |
+
|
| 99 |
+
# Compute the area of intersection
|
| 100 |
+
interArea = max(0, xB - xA) * max(0, yB - yA)
|
| 101 |
+
|
| 102 |
+
# Compute the area of both bounding boxes
|
| 103 |
+
boxAArea = (boxA[2] - boxA[0]) * (boxA[3] - boxA[1])
|
| 104 |
+
boxBArea = (boxB[2] - boxB[0]) * (boxB[3] - boxB[1])
|
| 105 |
+
|
| 106 |
+
# Compute the area of union
|
| 107 |
+
unionArea = float(boxAArea + boxBArea - interArea)
|
| 108 |
+
|
| 109 |
+
# Return the IoU
|
| 110 |
+
return interArea / unionArea if unionArea > 0 else 0
|
| 111 |
+
|
| 112 |
@GPU
|
| 113 |
def analyze_and_visualize_layout(input_image: Image.Image, selected_model_name: str, prompt: str, use_greedy: bool, temperature: float, top_p: float, progress=gr.Progress(track_tqdm=True)):
|
| 114 |
"""
|
| 115 |
Takes an image and model parameters, runs inference, and returns a visualized image and raw text output.
|
| 116 |
+
Supports running a single model or mixing results from two models.
|
| 117 |
"""
|
| 118 |
if input_image is None:
|
| 119 |
return None, "Please upload an image first."
|
| 120 |
|
| 121 |
+
progress(0, desc="Resizing image...")
|
|
|
|
|
|
|
|
|
|
| 122 |
image = input_image.resize(TARGET_SIZE).convert("RGBA")
|
| 123 |
|
| 124 |
+
# --- Nested function to run inference on a given model ---
|
| 125 |
+
def run_inference(model_to_run, model_name_desc):
|
| 126 |
+
progress(0.1, desc=f"Preparing inputs for {model_name_desc}...")
|
| 127 |
+
messages = [{"role": "user", "content": [{"type": "image", "image": image}, {"type": "text", "text": prompt}]}]
|
| 128 |
+
text = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
| 129 |
+
inputs = processor(text=[text], images=[image], padding=True, return_tensors="pt").to(model_to_run.device)
|
| 130 |
+
|
| 131 |
+
gen_kwargs = {"max_new_tokens": 4096}
|
| 132 |
+
if use_greedy:
|
| 133 |
+
gen_kwargs["do_sample"] = False
|
| 134 |
+
else:
|
| 135 |
+
gen_kwargs["do_sample"] = True
|
| 136 |
+
gen_kwargs["temperature"] = temperature
|
| 137 |
+
gen_kwargs["top_p"] = top_p
|
| 138 |
+
|
| 139 |
+
progress(0.5, desc=f"Generating layout data with {model_name_desc}...")
|
| 140 |
+
with torch.no_grad():
|
| 141 |
+
output_ids = model_to_run.generate(**inputs, **gen_kwargs)
|
| 142 |
|
| 143 |
+
raw_text = processor.batch_decode(output_ids[:, inputs.input_ids.shape[1]:], skip_special_tokens=True)[0]
|
| 144 |
+
|
| 145 |
+
try:
|
| 146 |
+
json_match = re.search(r"```json(.*?)```", raw_text, re.DOTALL)
|
| 147 |
+
json_str = json_match.group(1).strip() if json_match else raw_text.strip()
|
| 148 |
+
parsed_results = json.loads(json_str)
|
| 149 |
+
return parsed_results, raw_text
|
| 150 |
+
except (json.JSONDecodeError, AttributeError):
|
| 151 |
+
# Return raw text on failure for debugging
|
| 152 |
+
return None, raw_text
|
| 153 |
|
| 154 |
+
# --- Main logic: single model or mixing ---
|
| 155 |
+
if selected_model_name == MODEL_MIXING_NAME:
|
| 156 |
+
# Run both models
|
| 157 |
+
base_results, raw_text_base = run_inference(model_base, "Base Model")
|
| 158 |
+
enhanced_results, raw_text_enhanced = run_inference(model_enhanced, "Enhanced Model")
|
| 159 |
+
|
| 160 |
+
output_text = f"--- Base Model Output ---\n{raw_text_base}\n\n--- Enhanced Model Output ---\n{raw_text_enhanced}"
|
| 161 |
+
|
| 162 |
+
if base_results is None or enhanced_results is None:
|
| 163 |
+
return image.convert("RGB"), f"Failed to parse JSON from one or both models:\n\n{output_text}"
|
| 164 |
+
|
| 165 |
+
# Merge results
|
| 166 |
+
progress(0.8, desc="Merging results from both models...")
|
| 167 |
+
merged_results = list(base_results)
|
| 168 |
+
base_bboxes = [item['bbox_2d'] for item in base_results if 'bbox_2d' in item]
|
| 169 |
+
|
| 170 |
+
for enhanced_item in enhanced_results:
|
| 171 |
+
if 'bbox_2d' not in enhanced_item: continue
|
| 172 |
+
|
| 173 |
+
is_duplicate = False
|
| 174 |
+
for base_bbox in base_bboxes:
|
| 175 |
+
iou = calculate_iou(enhanced_item['bbox_2d'], base_bbox)
|
| 176 |
+
if iou > 0.5: # IoU threshold for duplication
|
| 177 |
+
is_duplicate = True
|
| 178 |
+
break
|
| 179 |
+
|
| 180 |
+
if not is_duplicate:
|
| 181 |
+
merged_results.append(enhanced_item)
|
| 182 |
+
|
| 183 |
+
results = merged_results
|
| 184 |
+
|
| 185 |
+
else:
|
| 186 |
+
# Run a single model
|
| 187 |
+
model = model_base if selected_model_name == MODEL_BASE_NAME else model_enhanced
|
| 188 |
+
results, output_text = run_inference(model, selected_model_name)
|
| 189 |
+
if results is None:
|
| 190 |
+
return image.convert("RGB"), f"Failed to parse JSON from model output:\n\n{output_text}"
|
| 191 |
|
| 192 |
+
# --- Visualization ---
|
| 193 |
+
progress(0.9, desc="Visualizing final results...")
|
| 194 |
overlay = Image.new('RGBA', image.size, (255, 255, 255, 0))
|
| 195 |
draw = ImageDraw.Draw(overlay)
|
| 196 |
|
|
|
|
| 200 |
font = ImageFont.load_default()
|
| 201 |
|
| 202 |
for item in sorted(results, key=lambda x: x.get("order", 999)):
|
| 203 |
+
bbox = item.get("bbox_2d")
|
| 204 |
+
label = item.get("label", "other")
|
| 205 |
+
order = item.get("order", "")
|
| 206 |
if not bbox or len(bbox) != 4: continue
|
| 207 |
|
| 208 |
fill_color_rgba = LABEL_COLORS.get(label, LABEL_COLORS["other"])
|
|
|
|
| 224 |
def toggle_sampling_params(use_greedy):
|
| 225 |
"""Updates visibility of temperature and top-p sliders."""
|
| 226 |
is_visible = not use_greedy
|
| 227 |
+
return gr.update(visible=is_visible)
|
| 228 |
|
| 229 |
# --- 4. Gradio User Interface ---
|
| 230 |
with gr.Blocks(theme=gr.themes.Glass(), title="Academic Paper Layout Detection") as demo:
|
| 231 |
gr.Markdown("# 📄 Academic Paper Layout Detection")
|
| 232 |
+
gr.Markdown("Welcome! This tool uses Qwen2.5-VL models to detect layout components in academic papers. You can choose the **Latex2Layout** model, an **Enhanced** version, or **Mix** the results of both.")
|
| 233 |
gr.Markdown("<hr>")
|
| 234 |
|
| 235 |
with gr.Row():
|
|
|
|
| 239 |
output_image = gr.Image(type="pil", label="Analyzed Layout", interactive=False, height=700)
|
| 240 |
|
| 241 |
with gr.Row():
|
| 242 |
+
analyze_btn = gr.Button("✨ Analyze Layout", variant="primary", scale=1)
|
| 243 |
|
| 244 |
with gr.Accordion("Advanced Settings", open=False):
|
| 245 |
+
model_selector = gr.Radio(
|
| 246 |
+
choices=MODEL_CHOICES,
|
| 247 |
+
value=MODEL_MIXING_NAME, # Default to the new mixing mode
|
| 248 |
+
label="Select Model"
|
| 249 |
+
)
|
| 250 |
prompt_textbox = gr.Textbox(label="Prompt", value=DEFAULT_PROMPT, lines=5)
|
| 251 |
|
|
|
|
| 252 |
greedy_checkbox = gr.Checkbox(label="Use Greedy Decoding", value=True, info="Faster and deterministic. Uncheck to enable Temperature and Top-p.")
|
| 253 |
|
| 254 |
+
temp_slider = gr.Slider(minimum=0.0, maximum=2.0, step=0.05, value=0.7, label="Temperature")
|
| 255 |
+
top_p_slider = gr.Slider(minimum=0.0, maximum=1.0, step=0.05, value=0.9, label="Top-p")
|
|
|
|
|
|
|
| 256 |
|
| 257 |
+
output_text = gr.Textbox(label="Model Raw Output", lines=10, interactive=False, visible=True)
|
| 258 |
+
gr.Examples(examples=[["1.png"], ["2.png"], ["12.png"], ["13.png"], ["14.png"], ["11.png"], ["3.png"], ["7.png"], ["8.png"]], inputs=[input_image], label="Examples (Click to Run)")
|
| 259 |
gr.Markdown("<p style='text-align:center; color:grey;'>Powered by the Latex2Layout dataset by Feijiang Han</p>")
|
| 260 |
|
| 261 |
# --- Event Handlers ---
|
|
|
|
| 268 |
input_image.upload(fn=clear_outputs, inputs=None, outputs=[output_image, output_text])
|
| 269 |
input_image.clear(fn=clear_outputs, inputs=None, outputs=[output_image, output_text])
|
| 270 |
|
|
|
|
| 271 |
greedy_checkbox.change(
|
| 272 |
fn=toggle_sampling_params,
|
| 273 |
inputs=greedy_checkbox,
|