Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -12,14 +12,14 @@ import torch
|
|
12 |
import numpy as np
|
13 |
from PIL import Image
|
14 |
import cv2
|
15 |
-
import edge_tts
|
16 |
|
17 |
from transformers import (
|
18 |
-
AutoModelForCausalLM,
|
19 |
-
AutoTokenizer,
|
20 |
-
TextIteratorStreamer,
|
21 |
Qwen2VLForConditionalGeneration,
|
|
|
|
|
|
|
22 |
AutoProcessor,
|
|
|
23 |
)
|
24 |
from transformers.image_utils import load_image
|
25 |
|
@@ -30,271 +30,251 @@ MAX_INPUT_TOKEN_LENGTH = int(os.getenv("MAX_INPUT_TOKEN_LENGTH", "4096"))
|
|
30 |
|
31 |
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
32 |
|
33 |
-
# Load
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
torch_dtype=torch.
|
40 |
-
)
|
41 |
-
model.eval()
|
42 |
|
43 |
-
# Load
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
trust_remote_code=True,
|
49 |
torch_dtype=torch.float16
|
50 |
-
).to(
|
51 |
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
"@palomaneural": "es-US-PalomaNeural",
|
57 |
-
"@alonsoneural": "es-US-AlonsoNeural",
|
58 |
-
"@madhurneural": "hi-IN-MadhurNeural"
|
59 |
-
}
|
60 |
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
await communicate.save(output_file)
|
67 |
-
return output_file
|
68 |
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
if isinstance(msg, dict) and isinstance(msg.get("content"), str):
|
77 |
-
cleaned.append(msg)
|
78 |
-
return cleaned
|
79 |
|
80 |
def downsample_video(video_path):
|
81 |
"""
|
82 |
-
Downsamples the video to
|
83 |
Each frame is returned as a PIL image along with its timestamp.
|
84 |
"""
|
85 |
vidcap = cv2.VideoCapture(video_path)
|
86 |
total_frames = int(vidcap.get(cv2.CAP_PROP_FRAME_COUNT))
|
87 |
fps = vidcap.get(cv2.CAP_PROP_FPS)
|
88 |
frames = []
|
89 |
-
# Sample 10 evenly spaced frames.
|
90 |
frame_indices = np.linspace(0, total_frames - 1, 10, dtype=int)
|
91 |
for i in frame_indices:
|
92 |
vidcap.set(cv2.CAP_PROP_POS_FRAMES, i)
|
93 |
success, image = vidcap.read()
|
94 |
if success:
|
95 |
-
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
96 |
pil_image = Image.fromarray(image)
|
97 |
timestamp = round(i / fps, 2)
|
98 |
frames.append((pil_image, timestamp))
|
99 |
vidcap.release()
|
100 |
return frames
|
101 |
|
102 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
103 |
"""
|
104 |
-
|
105 |
-
The progress bar is styled as a light cyan animated bar.
|
106 |
"""
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
121 |
|
122 |
@spaces.GPU
|
123 |
-
def
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
"""
|
130 |
-
Generates
|
131 |
-
and Edge TTS when using the new tags @JennyNeural or @GuyNeural.
|
132 |
-
Special command:
|
133 |
-
- "@video-infer": triggers video processing using Imgscope-OCR
|
134 |
"""
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
|
|
146 |
|
147 |
-
|
148 |
-
|
149 |
-
prompt = text[len("@video-infer"):].strip() if not tts_voice else text
|
150 |
-
if files:
|
151 |
-
# Assume the first file is a video.
|
152 |
-
video_path = files[0]
|
153 |
-
frames = downsample_video(video_path)
|
154 |
-
messages = [
|
155 |
-
{"role": "system", "content": [{"type": "text", "text": "You are a helpful assistant."}]},
|
156 |
-
{"role": "user", "content": [{"type": "text", "text": prompt}]}
|
157 |
-
]
|
158 |
-
# Append each frame with its timestamp.
|
159 |
-
for frame in frames:
|
160 |
-
image, timestamp = frame
|
161 |
-
image_path = f"video_frame_{uuid.uuid4().hex}.png"
|
162 |
-
image.save(image_path)
|
163 |
-
messages[1]["content"].append({"type": "text", "text": f"Frame {timestamp}:"})
|
164 |
-
messages[1]["content"].append({"type": "image", "url": image_path})
|
165 |
-
else:
|
166 |
-
messages = [
|
167 |
-
{"role": "system", "content": [{"type": "text", "text": "You are a helpful assistant."}]},
|
168 |
-
{"role": "user", "content": [{"type": "text", "text": prompt}]}
|
169 |
-
]
|
170 |
-
# Enable truncation to avoid token/feature mismatch.
|
171 |
-
inputs = processor.apply_chat_template(
|
172 |
-
messages,
|
173 |
-
tokenize=True,
|
174 |
-
add_generation_prompt=True,
|
175 |
-
return_dict=True,
|
176 |
-
return_tensors="pt",
|
177 |
-
truncation=True,
|
178 |
-
max_length=MAX_INPUT_TOKEN_LENGTH
|
179 |
-
).to("cuda")
|
180 |
-
streamer = TextIteratorStreamer(processor, skip_prompt=True, skip_special_tokens=True)
|
181 |
-
generation_kwargs = {
|
182 |
-
**inputs,
|
183 |
-
"streamer": streamer,
|
184 |
-
"max_new_tokens": max_new_tokens,
|
185 |
-
"do_sample": True,
|
186 |
-
"temperature": temperature,
|
187 |
-
"top_p": top_p,
|
188 |
-
"top_k": top_k,
|
189 |
-
"repetition_penalty": repetition_penalty,
|
190 |
-
}
|
191 |
-
thread = Thread(target=model_m.generate, kwargs=generation_kwargs)
|
192 |
-
thread.start()
|
193 |
-
buffer = ""
|
194 |
-
yield progress_bar_html("Processing video with Imgscope-OCR")
|
195 |
-
for new_text in streamer:
|
196 |
-
buffer += new_text
|
197 |
-
buffer = buffer.replace("<|im_end|>", "")
|
198 |
-
time.sleep(0.01)
|
199 |
-
yield buffer
|
200 |
return
|
201 |
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
messages
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
# Normal text conversation processing with Pocket Llama.
|
240 |
-
conversation = clean_chat_history(chat_history)
|
241 |
-
conversation.append({"role": "user", "content": text})
|
242 |
-
input_ids = tokenizer.apply_chat_template(conversation, add_generation_prompt=True, return_tensors="pt")
|
243 |
-
if input_ids.shape[1] > MAX_INPUT_TOKEN_LENGTH:
|
244 |
-
input_ids = input_ids[:, -MAX_INPUT_TOKEN_LENGTH:]
|
245 |
-
gr.Warning(f"Trimmed input from conversation as it was longer than {MAX_INPUT_TOKEN_LENGTH} tokens.")
|
246 |
-
input_ids = input_ids.to(model.device)
|
247 |
-
streamer = TextIteratorStreamer(tokenizer, timeout=20.0, skip_prompt=True, skip_special_tokens=True)
|
248 |
-
generation_kwargs = {
|
249 |
-
"input_ids": input_ids,
|
250 |
-
"streamer": streamer,
|
251 |
-
"max_new_tokens": max_new_tokens,
|
252 |
-
"do_sample": True,
|
253 |
-
"top_p": top_p,
|
254 |
-
"top_k": top_k,
|
255 |
-
"temperature": temperature,
|
256 |
-
"num_beams": 1,
|
257 |
-
"repetition_penalty": repetition_penalty,
|
258 |
-
}
|
259 |
-
t = Thread(target=model.generate, kwargs=generation_kwargs)
|
260 |
-
t.start()
|
261 |
-
outputs = []
|
262 |
-
yield progress_bar_html("Processing With Galactic Qwen")
|
263 |
-
for new_text in streamer:
|
264 |
-
outputs.append(new_text)
|
265 |
-
yield "".join(outputs)
|
266 |
-
final_response = "".join(outputs)
|
267 |
-
yield final_response
|
268 |
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
|
|
|
|
273 |
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
298 |
|
299 |
if __name__ == "__main__":
|
300 |
-
demo.queue(max_size=
|
|
|
12 |
import numpy as np
|
13 |
from PIL import Image
|
14 |
import cv2
|
|
|
15 |
|
16 |
from transformers import (
|
|
|
|
|
|
|
17 |
Qwen2VLForConditionalGeneration,
|
18 |
+
Qwen2_5_VLForConditionalGeneration,
|
19 |
+
AutoModelForVision2Seq,
|
20 |
+
AutoModelForImageTextToText,
|
21 |
AutoProcessor,
|
22 |
+
TextIteratorStreamer,
|
23 |
)
|
24 |
from transformers.image_utils import load_image
|
25 |
|
|
|
30 |
|
31 |
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
32 |
|
33 |
+
# Load Nanonets-OCR-s
|
34 |
+
MODEL_ID_M = "nanonets/Nanonets-OCR-s"
|
35 |
+
processor_m = AutoProcessor.from_pretrained(MODEL_ID_M, trust_remote_code=True)
|
36 |
+
model_m = Qwen2_5_VLForConditionalGeneration.from_pretrained(
|
37 |
+
MODEL_ID_M,
|
38 |
+
trust_remote_code=True,
|
39 |
+
torch_dtype=torch.float16
|
40 |
+
).to(device).eval()
|
|
|
41 |
|
42 |
+
# Load SmolDocling-256M-preview
|
43 |
+
MODEL_ID_X = "ds4sd/SmolDocling-256M-preview"
|
44 |
+
processor_x = AutoProcessor.from_pretrained(MODEL_ID_X, trust_remote_code=True)
|
45 |
+
model_x = AutoModelForVision2Seq.from_pretrained(
|
46 |
+
MODEL_ID_X,
|
47 |
trust_remote_code=True,
|
48 |
torch_dtype=torch.float16
|
49 |
+
).to(device).eval()
|
50 |
|
51 |
+
#--------------------------------------------------------------------------------------#
|
52 |
+
#Load MonkeyOCR
|
53 |
+
MODEL_ID_G = "echo840/MonkeyOCR"
|
54 |
+
SUBFOLDER = "Recognition"
|
|
|
|
|
|
|
|
|
55 |
|
56 |
+
processor_g = AutoProcessor.from_pretrained(
|
57 |
+
MODEL_ID_G,
|
58 |
+
trust_remote_code=True,
|
59 |
+
subfolder=SUBFOLDER
|
60 |
+
)
|
|
|
|
|
61 |
|
62 |
+
model_g = Qwen2_5_VLForConditionalGeneration.from_pretrained(
|
63 |
+
MODEL_ID_G,
|
64 |
+
trust_remote_code=True,
|
65 |
+
subfolder=SUBFOLDER,
|
66 |
+
torch_dtype=torch.float16
|
67 |
+
).to(device).eval()
|
68 |
+
#--------------------------------------------------------------------------------------#
|
|
|
|
|
|
|
69 |
|
70 |
def downsample_video(video_path):
|
71 |
"""
|
72 |
+
Downsamples the video to evenly spaced frames.
|
73 |
Each frame is returned as a PIL image along with its timestamp.
|
74 |
"""
|
75 |
vidcap = cv2.VideoCapture(video_path)
|
76 |
total_frames = int(vidcap.get(cv2.CAP_PROP_FRAME_COUNT))
|
77 |
fps = vidcap.get(cv2.CAP_PROP_FPS)
|
78 |
frames = []
|
|
|
79 |
frame_indices = np.linspace(0, total_frames - 1, 10, dtype=int)
|
80 |
for i in frame_indices:
|
81 |
vidcap.set(cv2.CAP_PROP_POS_FRAMES, i)
|
82 |
success, image = vidcap.read()
|
83 |
if success:
|
84 |
+
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
85 |
pil_image = Image.fromarray(image)
|
86 |
timestamp = round(i / fps, 2)
|
87 |
frames.append((pil_image, timestamp))
|
88 |
vidcap.release()
|
89 |
return frames
|
90 |
|
91 |
+
@spaces.GPU
|
92 |
+
def generate_image(model_name: str, text: str, image: Image.Image,
|
93 |
+
max_new_tokens: int = 1024,
|
94 |
+
temperature: float = 0.6,
|
95 |
+
top_p: float = 0.9,
|
96 |
+
top_k: int = 50,
|
97 |
+
repetition_penalty: float = 1.2):
|
98 |
"""
|
99 |
+
Generates responses using the selected model for image input.
|
|
|
100 |
"""
|
101 |
+
if model_name == "Nanonets-OCR-s":
|
102 |
+
processor = processor_m
|
103 |
+
model = model_m
|
104 |
+
elif model_name == "SmolDocling-256M-preview":
|
105 |
+
processor = processor_x
|
106 |
+
model = model_x
|
107 |
+
elif model_name == "MonkeyOCR-Recognition":
|
108 |
+
processor = processor_g
|
109 |
+
model = model_g
|
110 |
+
else:
|
111 |
+
yield "Invalid model selected."
|
112 |
+
return
|
113 |
+
|
114 |
+
if image is None:
|
115 |
+
yield "Please upload an image."
|
116 |
+
return
|
117 |
+
|
118 |
+
messages = [{
|
119 |
+
"role": "user",
|
120 |
+
"content": [
|
121 |
+
{"type": "image", "image": image},
|
122 |
+
{"type": "text", "text": text},
|
123 |
+
]
|
124 |
+
}]
|
125 |
+
prompt_full = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
126 |
+
inputs = processor(
|
127 |
+
text=[prompt_full],
|
128 |
+
images=[image],
|
129 |
+
return_tensors="pt",
|
130 |
+
padding=True,
|
131 |
+
truncation=False,
|
132 |
+
max_length=MAX_INPUT_TOKEN_LENGTH
|
133 |
+
).to(device)
|
134 |
+
streamer = TextIteratorStreamer(processor, skip_prompt=True, skip_special_tokens=True)
|
135 |
+
generation_kwargs = {**inputs, "streamer": streamer, "max_new_tokens": max_new_tokens}
|
136 |
+
thread = Thread(target=model.generate, kwargs=generation_kwargs)
|
137 |
+
thread.start()
|
138 |
+
buffer = ""
|
139 |
+
for new_text in streamer:
|
140 |
+
buffer += new_text
|
141 |
+
buffer = buffer.replace("<|im_end|>", "")
|
142 |
+
time.sleep(0.01)
|
143 |
+
yield buffer
|
144 |
|
145 |
@spaces.GPU
|
146 |
+
def generate_video(model_name: str, text: str, video_path: str,
|
147 |
+
max_new_tokens: int = 1024,
|
148 |
+
temperature: float = 0.6,
|
149 |
+
top_p: float = 0.9,
|
150 |
+
top_k: int = 50,
|
151 |
+
repetition_penalty: float = 1.2):
|
152 |
"""
|
153 |
+
Generates responses using the selected model for video input.
|
|
|
|
|
|
|
154 |
"""
|
155 |
+
if model_name == "Nanonets-OCR-s":
|
156 |
+
processor = processor_m
|
157 |
+
model = model_m
|
158 |
+
elif model_name == "SmolDocling-256M-preview":
|
159 |
+
processor = processor_x
|
160 |
+
model = model_x
|
161 |
+
elif model_name == "MonkeyOCR-Recognition":
|
162 |
+
processor = processor_g
|
163 |
+
model = model_g
|
164 |
+
else:
|
165 |
+
yield "Invalid model selected."
|
166 |
+
return
|
167 |
|
168 |
+
if video_path is None:
|
169 |
+
yield "Please upload a video."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
170 |
return
|
171 |
|
172 |
+
frames = downsample_video(video_path)
|
173 |
+
messages = [
|
174 |
+
{"role": "system", "content": [{"type": "text", "text": "You are a helpful assistant."}]},
|
175 |
+
{"role": "user", "content": [{"type": "text", "text": text}]}
|
176 |
+
]
|
177 |
+
for frame in frames:
|
178 |
+
image, timestamp = frame
|
179 |
+
messages[1]["content"].append({"type": "text", "text": f"Frame {timestamp}:"})
|
180 |
+
messages[1]["content"].append({"type": "image", "image": image})
|
181 |
+
inputs = processor.apply_chat_template(
|
182 |
+
messages,
|
183 |
+
tokenize=True,
|
184 |
+
add_generation_prompt=True,
|
185 |
+
return_dict=True,
|
186 |
+
return_tensors="pt",
|
187 |
+
truncation=False,
|
188 |
+
max_length=MAX_INPUT_TOKEN_LENGTH
|
189 |
+
).to(device)
|
190 |
+
streamer = TextIteratorStreamer(processor, skip_prompt=True, skip_special_tokens=True)
|
191 |
+
generation_kwargs = {
|
192 |
+
**inputs,
|
193 |
+
"streamer": streamer,
|
194 |
+
"max_new_tokens": max_new_tokens,
|
195 |
+
"do_sample": True,
|
196 |
+
"temperature": temperature,
|
197 |
+
"top_p": top_p,
|
198 |
+
"top_k": top_k,
|
199 |
+
"repetition_penalty": repetition_penalty,
|
200 |
+
}
|
201 |
+
thread = Thread(target=model.generate, kwargs=generation_kwargs)
|
202 |
+
thread.start()
|
203 |
+
buffer = ""
|
204 |
+
for new_text in streamer:
|
205 |
+
buffer += new_text
|
206 |
+
buffer = buffer.replace("<|im_end|>", "")
|
207 |
+
time.sleep(0.01)
|
208 |
+
yield buffer
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
209 |
|
210 |
+
# Define examples for image and video inference
|
211 |
+
image_examples = [
|
212 |
+
["fill the correct numbers", "example/image3.png"],
|
213 |
+
["ocr the image", "example/image1.png"],
|
214 |
+
["explain the scene", "example/image2.jpg"],
|
215 |
+
]
|
216 |
|
217 |
+
video_examples = [
|
218 |
+
["Explain the ad in detail", "example/1.mp4"],
|
219 |
+
["Identify the main actions in the coca cola ad...", "example/2.mp4"]
|
220 |
+
]
|
221 |
+
|
222 |
+
css = """
|
223 |
+
.submit-btn {
|
224 |
+
background-color: #2980b9 !important;
|
225 |
+
color: white !important;
|
226 |
+
}
|
227 |
+
.submit-btn:hover {
|
228 |
+
background-color: #3498db !important;
|
229 |
+
}
|
230 |
+
"""
|
231 |
+
|
232 |
+
# Create the Gradio Interface
|
233 |
+
with gr.Blocks(css=css, theme="bethecloud/storj_theme") as demo:
|
234 |
+
gr.Markdown("# **[core OCR](https://huggingface.co/collections/prithivMLmods/core-and-docscope-ocr-models-6816d7f1bde3f911c6c852bc)**")
|
235 |
+
with gr.Row():
|
236 |
+
with gr.Column():
|
237 |
+
with gr.Tabs():
|
238 |
+
with gr.TabItem("Image Inference"):
|
239 |
+
image_query = gr.Textbox(label="Query Input", placeholder="Enter your query here...")
|
240 |
+
image_upload = gr.Image(type="pil", label="Image")
|
241 |
+
image_submit = gr.Button("Submit", elem_classes="submit-btn")
|
242 |
+
gr.Examples(
|
243 |
+
examples=image_examples,
|
244 |
+
inputs=[image_query, image_upload]
|
245 |
+
)
|
246 |
+
with gr.TabItem("Video Inference"):
|
247 |
+
video_query = gr.Textbox(label="Query Input", placeholder="Enter your query here...")
|
248 |
+
video_upload = gr.Video(label="Video")
|
249 |
+
video_submit = gr.Button("Submit", elem_classes="submit-btn")
|
250 |
+
gr.Examples(
|
251 |
+
examples=video_examples,
|
252 |
+
inputs=[video_query, video_upload]
|
253 |
+
)
|
254 |
+
with gr.Accordion("Advanced options", open=False):
|
255 |
+
max_new_tokens = gr.Slider(label="Max new tokens", minimum=1, maximum=MAX_MAX_NEW_TOKENS, step=1, value=DEFAULT_MAX_NEW_TOKENS)
|
256 |
+
temperature = gr.Slider(label="Temperature", minimum=0.1, maximum=4.0, step=0.1, value=0.6)
|
257 |
+
top_p = gr.Slider(label="Top-p (nucleus sampling)", minimum=0.05, maximum=1.0, step=0.05, value=0.9)
|
258 |
+
top_k = gr.Slider(label="Top-k", minimum=1, maximum=1000, step=1, value=50)
|
259 |
+
repetition_penalty = gr.Slider(label="Repetition penalty", minimum=1.0, maximum=2.0, step=0.05, value=1.2)
|
260 |
+
with gr.Column():
|
261 |
+
output = gr.Textbox(label="Output", interactive=False, lines=3, scale=2)
|
262 |
+
model_choice = gr.Radio(
|
263 |
+
choices=["Nanonets-OCR-s", "MonkeyOCR-Recognition", "SmolDocling-256M-preview"],
|
264 |
+
label="Select Model",
|
265 |
+
value="Nanonets-OCR-s"
|
266 |
+
)
|
267 |
+
|
268 |
+
image_submit.click(
|
269 |
+
fn=generate_image,
|
270 |
+
inputs=[model_choice, image_query, image_upload, max_new_tokens, temperature, top_p, top_k, repetition_penalty],
|
271 |
+
outputs=output
|
272 |
+
)
|
273 |
+
video_submit.click(
|
274 |
+
fn=generate_video,
|
275 |
+
inputs=[model_choice, video_query, video_upload, max_new_tokens, temperature, top_p, top_k, repetition_penalty],
|
276 |
+
outputs=output
|
277 |
+
)
|
278 |
|
279 |
if __name__ == "__main__":
|
280 |
+
demo.queue(max_size=30).launch(share=True, mcp_server=True, ssr_mode=False, show_error=True)
|