jon-fernandes commited on
Commit
2b36c21
·
verified ·
1 Parent(s): 35c19d2

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +26 -5
app.py CHANGED
@@ -3,7 +3,7 @@ import base64
3
  from queue import Queue
4
  import threading
5
  import torch
6
- from PIL import Image
7
  from transformers import AutoProcessor, MiniCPMV4_6ForConditionalGeneration, TextIteratorStreamer
8
  import gradio as gr
9
 
@@ -21,6 +21,13 @@ GPT_MAX_COMPLETION_TOKENS = 4096
21
  GPT_REASONING_EFFORT = "none"
22
  NOTES_PROMPT = "Transcribe the musical notes in this image. Return only the transcription."
23
 
 
 
 
 
 
 
 
24
  print("Loading processor...")
25
  processor = AutoProcessor.from_pretrained(ORIGINAL_MODEL_ID, trust_remote_code=True)
26
 
@@ -223,7 +230,7 @@ def predict_all(image_path):
223
  yield message, message, message
224
  return
225
 
226
- image = Image.open(image_path).convert("RGB")
227
  updates = Queue()
228
  outputs = ["", "", ""]
229
 
@@ -268,11 +275,20 @@ with gr.Blocks(title="Noteworthy — Sheet Music Transcription") as demo:
268
  """
269
  # Noteworthy
270
  Sheet Music Transcription
271
- Upload an image of sheet music and click **Transcribe Music** to compare models.
272
  """
273
  )
274
 
275
- image_input = gr.Image(type="filepath", label="Upload Sheet Music Image")
 
 
 
 
 
 
 
 
 
276
  gr.Examples(
277
  examples=[
278
  ["examples/000100005-1_1_1.png"],
@@ -303,4 +319,9 @@ with gr.Blocks(title="Noteworthy — Sheet Music Transcription") as demo:
303
  outputs=[finetuned_output, original_output, gpt_output],
304
  )
305
 
306
- demo.launch(theme=gr.themes.Soft())
 
 
 
 
 
 
3
  from queue import Queue
4
  import threading
5
  import torch
6
+ from PIL import Image, ImageOps
7
  from transformers import AutoProcessor, MiniCPMV4_6ForConditionalGeneration, TextIteratorStreamer
8
  import gradio as gr
9
 
 
21
  GPT_REASONING_EFFORT = "none"
22
  NOTES_PROMPT = "Transcribe the musical notes in this image. Return only the transcription."
23
 
24
+
25
+ def env_flag(name: str, default: bool = False) -> bool:
26
+ value = os.environ.get(name)
27
+ if value is None:
28
+ return default
29
+ return value.strip().lower() in {"1", "true", "yes", "on"}
30
+
31
  print("Loading processor...")
32
  processor = AutoProcessor.from_pretrained(ORIGINAL_MODEL_ID, trust_remote_code=True)
33
 
 
230
  yield message, message, message
231
  return
232
 
233
+ image = ImageOps.exif_transpose(Image.open(image_path)).convert("RGB")
234
  updates = Queue()
235
  outputs = ["", "", ""]
236
 
 
275
  """
276
  # Noteworthy
277
  Sheet Music Transcription
278
+ Take a photo or upload sheet music, then click **Transcribe Music** to compare models.
279
  """
280
  )
281
 
282
+ gr.Markdown(
283
+ "Camera: allow camera access, frame the whole page, then tap the round capture button in the image box."
284
+ )
285
+ image_input = gr.Image(
286
+ type="filepath",
287
+ label="Sheet Music Image - camera captures are mirrored for correct orientation",
288
+ sources=["webcam", "upload", "clipboard"],
289
+ webcam_options=gr.WebcamOptions(mirror=True),
290
+ placeholder="Use Camera to frame the sheet music, then tap the capture button.",
291
+ )
292
  gr.Examples(
293
  examples=[
294
  ["examples/000100005-1_1_1.png"],
 
319
  outputs=[finetuned_output, original_output, gpt_output],
320
  )
321
 
322
+ demo.launch(
323
+ theme=gr.themes.Soft(),
324
+ server_name=os.environ.get("GRADIO_SERVER_NAME", "0.0.0.0"),
325
+ server_port=int(os.environ.get("GRADIO_SERVER_PORT", "7860")),
326
+ share=env_flag("GRADIO_SHARE"),
327
+ )