a0a7 commited on
Commit
f199650
·
2 Parent(s): 0c41507 5a1cb9f

Merge branch 'main' of https://huggingface.co/spaces/a0a7/gregg-recognition

Browse files
Files changed (1) hide show
  1. app.py +33 -44
app.py CHANGED
@@ -2,54 +2,43 @@ import gradio as gr
2
  import random
3
  from PIL import Image
4
 
5
- class GreggRecognitionDemo:
6
- def __init__(self):
7
- print("🚀 Initializing Gregg Shorthand Recognition Demo")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
 
9
- def recognize_shorthand(self, image):
10
- """Simulate shorthand recognition for demo purposes"""
11
- if image is None:
12
- return "Please upload an image to begin recognition.", None
13
 
14
- try:
15
- # Demo recognition results
16
- demo_results = [
17
- "wonderful day",
18
- "excellent work",
19
- "shorthand notation",
20
- "beautiful writing",
21
- "stenography practice",
22
- "business correspondence",
23
- "court reporting",
24
- "note taking system"
25
- ]
26
-
27
- # Simulate processing
28
- result = random.choice(demo_results)
29
- confidence = random.uniform(0.75, 0.95)
30
-
31
- # Resize for display
32
- display_image = image.copy()
33
- if display_image.size[0] > 600 or display_image.size[1] > 400:
34
- display_image.thumbnail((600, 400), Image.Resampling.LANCZOS)
35
-
36
- formatted_result = f"**Recognized Text:** {result}\n**Confidence:** {confidence:.1%}"
37
-
38
- return formatted_result, display_image
39
-
40
- except Exception as e:
41
- return f"Error processing image: {str(e)}", image
42
-
43
- # Initialize demo
44
- demo_model = GreggRecognitionDemo()
45
-
46
- def process_image(image):
47
- """Process uploaded image"""
48
- return demo_model.recognize_shorthand(image)
49
 
50
- # Create simple interface
51
  demo = gr.Interface(
52
- fn=process_image,
53
  inputs=gr.Image(type="pil", label="Upload Gregg Shorthand Image"),
54
  outputs=[
55
  gr.Textbox(label="Recognition Result", lines=3),
 
2
  import random
3
  from PIL import Image
4
 
5
+ # Create simple interface
6
+ def recognize_image(image):
7
+ """Main function for the Gradio interface"""
8
+ if image is None:
9
+ return "Please upload an image to begin recognition.", None
10
+
11
+ try:
12
+ # Demo recognition results
13
+ demo_results = [
14
+ "wonderful day",
15
+ "excellent work",
16
+ "shorthand notation",
17
+ "beautiful writing",
18
+ "stenography practice",
19
+ "business correspondence",
20
+ "court reporting",
21
+ "note taking system"
22
+ ]
23
 
24
+ # Simulate processing
25
+ result = random.choice(demo_results)
26
+ confidence = random.uniform(0.75, 0.95)
 
27
 
28
+ # Resize for display
29
+ display_image = image.copy()
30
+ if display_image.size[0] > 600 or display_image.size[1] > 400:
31
+ display_image.thumbnail((600, 400), Image.Resampling.LANCZOS)
32
+
33
+ formatted_result = f"**Recognized Text:** {result}\n**Confidence:** {confidence:.1%}"
34
+
35
+ return formatted_result, display_image
36
+
37
+ except Exception as e:
38
+ return f"Error processing image: {str(e)}", image
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
 
 
40
  demo = gr.Interface(
41
+ fn=recognize_image,
42
  inputs=gr.Image(type="pil", label="Upload Gregg Shorthand Image"),
43
  outputs=[
44
  gr.Textbox(label="Recognition Result", lines=3),