Spaces:
Sleeping
Sleeping
Merge branch 'main' of https://huggingface.co/spaces/a0a7/gregg-recognition
Browse files
app.py
CHANGED
@@ -2,54 +2,43 @@ import gradio as gr
|
|
2 |
import random
|
3 |
from PIL import Image
|
4 |
|
5 |
-
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
return "Please upload an image to begin recognition.", None
|
13 |
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
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=
|
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),
|