Spaces:
Sleeping
Sleeping
fix space
Browse files
README.md
CHANGED
@@ -24,20 +24,9 @@ models:
|
|
24 |
|
25 |
This is an interactive demo for recognizing Gregg shorthand notation from images.
|
26 |
|
27 |
-
## Features
|
28 |
-
|
29 |
-
- Upload images containing Gregg shorthand
|
30 |
-
- Real-time text recognition
|
31 |
-
- Confidence scoring
|
32 |
-
- Support for various image formats
|
33 |
-
- Historical document processing
|
34 |
-
|
35 |
## How to Use
|
36 |
|
37 |
-
|
38 |
-
2. Adjust the confidence threshold if needed
|
39 |
-
3. Click "Recognize" to process the image
|
40 |
-
4. View the recognized text and confidence score
|
41 |
|
42 |
## Model Information
|
43 |
|
@@ -48,17 +37,6 @@ This demo uses the Gregg Recognition model trained specifically for Gregg shorth
|
|
48 |
- Advanced pattern recognition techniques
|
49 |
- Specialized preprocessing for shorthand symbols
|
50 |
|
51 |
-
## About Gregg Shorthand
|
52 |
-
|
53 |
-
Gregg shorthand is a system of stenography invented by John Robert Gregg in 1888. It was widely used for:
|
54 |
-
|
55 |
-
- Court reporting
|
56 |
-
- Business correspondence
|
57 |
-
- Note-taking
|
58 |
-
- Administrative documentation
|
59 |
-
|
60 |
-
This model helps digitize historical shorthand documents and assists in stenography education.
|
61 |
-
|
62 |
## Technical Details
|
63 |
|
64 |
- **Model Type**: Image-to-Text Recognition
|
|
|
24 |
|
25 |
This is an interactive demo for recognizing Gregg shorthand notation from images.
|
26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
## How to Use
|
28 |
|
29 |
+
Upload an image containing Gregg shorthand notation and submit
|
|
|
|
|
|
|
30 |
|
31 |
## Model Information
|
32 |
|
|
|
37 |
- Advanced pattern recognition techniques
|
38 |
- Specialized preprocessing for shorthand symbols
|
39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
## Technical Details
|
41 |
|
42 |
- **Model Type**: Image-to-Text Recognition
|
app.py
CHANGED
@@ -5,20 +5,26 @@ from PIL import Image
|
|
5 |
|
6 |
# Import the actual recognition model
|
7 |
try:
|
|
|
8 |
from gregg_recognition import GreggRecognition
|
|
|
9 |
MODEL_AVAILABLE = True
|
10 |
-
except ImportError:
|
|
|
11 |
MODEL_AVAILABLE = False
|
12 |
print("Warning: gregg_recognition model not available, using demo mode")
|
13 |
|
14 |
# Initialize the model
|
15 |
if MODEL_AVAILABLE:
|
16 |
try:
|
|
|
17 |
# Initialize with image_to_text model (our disguised memorization model)
|
18 |
recognizer = GreggRecognition(model_type="image_to_text", device="cpu")
|
19 |
-
print("
|
20 |
except Exception as e:
|
21 |
-
print(f"
|
|
|
|
|
22 |
MODEL_AVAILABLE = False
|
23 |
recognizer = None
|
24 |
else:
|
@@ -35,20 +41,36 @@ def recognize_image(image):
|
|
35 |
if display_image.size[0] > 600 or display_image.size[1] > 400:
|
36 |
display_image.thumbnail((600, 400), Image.Resampling.LANCZOS)
|
37 |
|
|
|
|
|
38 |
if MODEL_AVAILABLE and recognizer is not None:
|
|
|
39 |
# Use the actual model
|
40 |
# Save image temporarily
|
41 |
with tempfile.NamedTemporaryFile(suffix='.png', delete=False) as tmp_file:
|
42 |
-
|
43 |
|
|
|
|
|
|
|
|
|
44 |
# Run recognition
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
os.unlink(tmp_file.name)
|
49 |
-
|
50 |
return result if result else "No text detected", display_image
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
else:
|
|
|
52 |
# Fallback demo mode
|
53 |
import random
|
54 |
demo_results = [
|
@@ -65,20 +87,21 @@ def recognize_image(image):
|
|
65 |
return f"[Demo Mode] {result}", display_image
|
66 |
|
67 |
except Exception as e:
|
|
|
68 |
return f"Error: {str(e)}", image
|
69 |
|
70 |
# Create interface with minimal configuration
|
71 |
demo = gr.Interface(
|
72 |
fn=recognize_image,
|
73 |
inputs=gr.Image(type="pil", sources=["upload", "clipboard"]),
|
74 |
-
outputs=[gr.Textbox()
|
75 |
title="Gregg Shorthand Recognition",
|
76 |
-
description="
|
77 |
)
|
78 |
|
79 |
if __name__ == "__main__":
|
80 |
print(f"π§ Model Status: {'Available' if MODEL_AVAILABLE else 'Demo Mode'}")
|
81 |
if MODEL_AVAILABLE:
|
82 |
-
print(f"
|
83 |
-
print(f"
|
84 |
demo.launch()
|
|
|
5 |
|
6 |
# Import the actual recognition model
|
7 |
try:
|
8 |
+
print("Attempting to import gregg_recognition...")
|
9 |
from gregg_recognition import GreggRecognition
|
10 |
+
print("Import successful")
|
11 |
MODEL_AVAILABLE = True
|
12 |
+
except ImportError as e:
|
13 |
+
print(f"Import failed: {e}")
|
14 |
MODEL_AVAILABLE = False
|
15 |
print("Warning: gregg_recognition model not available, using demo mode")
|
16 |
|
17 |
# Initialize the model
|
18 |
if MODEL_AVAILABLE:
|
19 |
try:
|
20 |
+
print("Initializing model")
|
21 |
# Initialize with image_to_text model (our disguised memorization model)
|
22 |
recognizer = GreggRecognition(model_type="image_to_text", device="cpu")
|
23 |
+
print("model loaded successfully")
|
24 |
except Exception as e:
|
25 |
+
print(f"Error loading model: {e}")
|
26 |
+
import traceback
|
27 |
+
traceback.print_exc()
|
28 |
MODEL_AVAILABLE = False
|
29 |
recognizer = None
|
30 |
else:
|
|
|
41 |
if display_image.size[0] > 600 or display_image.size[1] > 400:
|
42 |
display_image.thumbnail((600, 400), Image.Resampling.LANCZOS)
|
43 |
|
44 |
+
print(f"π Processing image... Model available: {MODEL_AVAILABLE}")
|
45 |
+
|
46 |
if MODEL_AVAILABLE and recognizer is not None:
|
47 |
+
print("π Using actual model for recognition")
|
48 |
# Use the actual model
|
49 |
# Save image temporarily
|
50 |
with tempfile.NamedTemporaryFile(suffix='.png', delete=False) as tmp_file:
|
51 |
+
tmp_path = tmp_file.name
|
52 |
|
53 |
+
# Save image outside the context manager
|
54 |
+
image.save(tmp_path)
|
55 |
+
|
56 |
+
try:
|
57 |
# Run recognition
|
58 |
+
print(f"Running recognition on: {tmp_path}")
|
59 |
+
result = recognizer.recognize(tmp_path)
|
60 |
+
print(f"Recognition result: {result}")
|
|
|
|
|
61 |
return result if result else "No text detected", display_image
|
62 |
+
finally:
|
63 |
+
# Clean up - try multiple times if file is locked
|
64 |
+
import time
|
65 |
+
for attempt in range(3):
|
66 |
+
try:
|
67 |
+
if os.path.exists(tmp_path):
|
68 |
+
os.unlink(tmp_path)
|
69 |
+
break
|
70 |
+
except (PermissionError, OSError):
|
71 |
+
time.sleep(0.1) # Wait briefly and retry
|
72 |
else:
|
73 |
+
print("Using demo mode (model not available)")
|
74 |
# Fallback demo mode
|
75 |
import random
|
76 |
demo_results = [
|
|
|
87 |
return f"[Demo Mode] {result}", display_image
|
88 |
|
89 |
except Exception as e:
|
90 |
+
print(f"Error in recognition: {e}")
|
91 |
return f"Error: {str(e)}", image
|
92 |
|
93 |
# Create interface with minimal configuration
|
94 |
demo = gr.Interface(
|
95 |
fn=recognize_image,
|
96 |
inputs=gr.Image(type="pil", sources=["upload", "clipboard"]),
|
97 |
+
outputs=[gr.Textbox()],
|
98 |
title="Gregg Shorthand Recognition",
|
99 |
+
description="upload an image of gregg shorthand and the gregg-recognition model will do its best to translate the image into text."
|
100 |
)
|
101 |
|
102 |
if __name__ == "__main__":
|
103 |
print(f"π§ Model Status: {'Available' if MODEL_AVAILABLE else 'Demo Mode'}")
|
104 |
if MODEL_AVAILABLE:
|
105 |
+
print(f"Model Type: image_to_text")
|
106 |
+
print(f"Device: cpu")
|
107 |
demo.launch()
|
gregg_recognition/__pycache__/__init__.cpython-313.pyc
CHANGED
Binary files a/gregg_recognition/__pycache__/__init__.cpython-313.pyc and b/gregg_recognition/__pycache__/__init__.cpython-313.pyc differ
|
|
gregg_recognition/__pycache__/recognizer.cpython-313.pyc
CHANGED
Binary files a/gregg_recognition/__pycache__/recognizer.cpython-313.pyc and b/gregg_recognition/__pycache__/recognizer.cpython-313.pyc differ
|
|