a0a7 commited on
Commit
0c41507
ยท
1 Parent(s): ba119b1
Files changed (2) hide show
  1. app.py +77 -0
  2. app_simple.py +0 -77
app.py CHANGED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 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),
56
+ gr.Image(label="Processed Image")
57
+ ],
58
+ title="๐Ÿ–‹๏ธ Gregg Shorthand Recognition",
59
+ description="Upload an image of Gregg shorthand notation to convert it to readable text!",
60
+ article="""
61
+ ### About This Demo
62
+ This is a demonstration of Gregg shorthand recognition using AI.
63
+ Gregg shorthand was a popular stenographic writing system used for over a century.
64
+
65
+ **Tips for best results:**
66
+ - Use clear, high-contrast images
67
+ - Ensure good lighting
68
+ - Crop to focus on the shorthand text
69
+
70
+ For more information, visit the [GitHub repository](https://github.com/a0a7/GreggRecognition).
71
+ """,
72
+ examples=None,
73
+ cache_examples=False
74
+ )
75
+
76
+ if __name__ == "__main__":
77
+ demo.launch()
app_simple.py DELETED
@@ -1,77 +0,0 @@
1
- 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),
56
- gr.Image(label="Processed Image")
57
- ],
58
- title="๐Ÿ–‹๏ธ Gregg Shorthand Recognition",
59
- description="Upload an image of Gregg shorthand notation to convert it to readable text!",
60
- article="""
61
- ### About This Demo
62
- This is a demonstration of Gregg shorthand recognition using AI.
63
- Gregg shorthand was a popular stenographic writing system used for over a century.
64
-
65
- **Tips for best results:**
66
- - Use clear, high-contrast images
67
- - Ensure good lighting
68
- - Crop to focus on the shorthand text
69
-
70
- For more information, visit the [GitHub repository](https://github.com/a0a7/GreggRecognition).
71
- """,
72
- examples=None,
73
- cache_examples=False
74
- )
75
-
76
- if __name__ == "__main__":
77
- demo.launch()