Tonic commited on
Commit
2cd1f0b
·
unverified ·
1 Parent(s): fa528ee

add res , remove files

Browse files
Files changed (3) hide show
  1. app.py +1 -1
  2. content/index.md +0 -53
  3. notes.py +0 -92
app.py CHANGED
@@ -147,7 +147,7 @@ def cleanup_old_files():
147
  if current_time - file_path.stat().st_mtime > 3600: # 1 hour
148
  file_path.unlink()
149
 
150
- with gr.Blocks() as demo:
151
  with gr.Row():
152
  gr.Markdown(title)
153
 
 
147
  if current_time - file_path.stat().st_mtime > 3600: # 1 hour
148
  file_path.unlink()
149
 
150
+ with gr.Blocks(theme=gr.themes.Base()) as demo:
151
  with gr.Row():
152
  gr.Markdown(title)
153
 
content/index.md DELETED
@@ -1,53 +0,0 @@
1
- ---
2
- title: "🙋🏻‍♂️Welcome to Tonic's🫴🏻📸GOT-OCR"
3
- ---
4
-
5
- # GOT-OCR Model Overview
6
-
7
- The **GOT-OCR model** is a cutting-edge OCR system with **580M parameters**, designed to process a wide range of "characters." Equipped with a **high-compression encoder** and a **long-context decoder**, it excels in both scene and document-style images. The model supports **multi-page** and **dynamic resolution OCR**, enhancing its versatility.
8
-
9
- ### Output Formats
10
-
11
- The model can generate results in several formats:
12
-
13
- - **Plain Text**
14
- - **Markdown**
15
- - **TikZ diagrams**
16
- - **Molecular SMILES strings**
17
-
18
- Additionally, **interactive OCR** enables users to define regions of interest via **coordinates** or **colors**.
19
-
20
- ## Key Features
21
-
22
- - **Plain Text OCR**: Extracts text from images.
23
- - **Formatted Text OCR**: Retains the original formatting, including tables and formulas.
24
- - **Fine-grained OCR**: Offers box-based and color-based OCR for precision in specific regions.
25
- - **Multi-crop OCR**: Handles multiple cropped sections within an image.
26
- - **Rendered Formatted OCR**: Outputs in markdown, TikZ, SMILES, and more, with rendered formatting.
27
-
28
- ## Supported Content Types
29
-
30
- - Plain text
31
- - Math/molecular formulas
32
- - Tables and charts
33
- - Sheet music
34
- - Geometric shapes
35
-
36
- ## How to Use
37
-
38
- 1. Select a task from the dropdown menu.
39
- 2. Upload an image.
40
- 3. (Optional) Adjust parameters based on the selected task.
41
- 4. Click **Process** to view the results.
42
-
43
- ### Model Information
44
-
45
- - **Model Name**: GOT-OCR 2.0
46
- - **Hugging Face Repository**: [ucaslcl/GOT-OCR2_0](https://huggingface.co/ucaslcl/GOT-OCR2_0)
47
- - **Environment**: CUDA 11.8 + PyTorch 2.0.1
48
-
49
- ---
50
-
51
- ### Join us :
52
-
53
- 🌟TeamTonic🌟 is always making cool demos! Join our active builder's 🛠️community 👻 [![Join us on Discord](https://img.shields.io/discord/1109943800132010065?label=Discord&logo=discord&style=flat-square)](https://discord.gg/qdfnvSPcqP) On 🤗Huggingface:[MultiTransformer](https://huggingface.co/MultiTransformer) On 🌐Github: [Tonic-AI](https://github.com/tonic-ai) & contribute to🌟 [Build Tonic](https://git.tonic-ai.com/contribute)🤗Big thanks to Yuvi Sharma and all the folks at huggingface for the community grant 🤗
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
notes.py DELETED
@@ -1,92 +0,0 @@
1
- def ocr_demo(image, task, ocr_type, ocr_box, ocr_color):
2
- res, html_content = process_image(image, task, ocr_type, ocr_box, ocr_color)
3
-
4
- res = f"$$ {res} $$"
5
- # res = res.replace("$$ \\begin{tabular}", "\\begin{tabular}")
6
- # res = res.replace("\\end{tabular} $$", "\\end{tabular}")
7
- # res = res.replace("\\(", "")
8
- # res = res.replace("\\)", "")
9
-
10
- if html_content:
11
- html_string = f'<iframe srcdoc="{html_content}" width="100%" height="600px"></iframe>'
12
- return res, html_string
13
- return res, None
14
-
15
- @spaces.GPU
16
- def process_image(image, task, ocr_type=None, ocr_box=None, ocr_color=None):
17
- demo_html = os.path.join(results_folder, "demo.html")
18
- html_file = os.path.join(results_folder, f"{task.replace(' ', '_').lower()}.html")
19
- tikz_file = os.path.join(results_folder, "tikz.html")
20
-
21
- unique_id = str(uuid.uuid4())
22
-
23
- with tempfile.NamedTemporaryFile(mode='w+', suffix='.html', delete=False, dir=results_folder) as temp_file:
24
- temp_html_path = temp_file.name
25
-
26
- if task == "Plain Text OCR":
27
- res = model.chat(tokenizer, image, ocr_type='ocr')
28
- return res, None, unique_id
29
- else:
30
- if task == "Format Text OCR":
31
- res = model.chat(tokenizer, image, ocr_type='format', render=True, save_render_file=temp_html_path)
32
- elif task == "Fine-grained OCR (Box)":
33
- res = model.chat(tokenizer, image, ocr_type=ocr_type, ocr_box=ocr_box, render=True, save_render_file=temp_html_path)
34
- elif task == "Fine-grained OCR (Color)":
35
- res = model.chat(tokenizer, image, ocr_type=ocr_type, ocr_color=ocr_color, render=True, save_render_file=temp_html_path)
36
- elif task == "Multi-crop OCR":
37
- res = model.chat_crop(tokenizer, image, ocr_type='format', render=True, save_render_file=temp_html_path)
38
- elif task == "Render Formatted OCR":
39
- res = model.chat(tokenizer, image, ocr_type='format', render=True, save_render_file=temp_html_path)
40
-
41
- # html_content = None
42
- if os.path.exists(temp_html_path):
43
- with open(temp_html_path, 'r') as f:
44
- html_content = f.read()
45
- if os.path.exists(demo_html):
46
- with open(demo_html, 'r') as f:
47
- html_content = f.read()
48
- elif os.path.exists(html_file):
49
- with open(html_file, 'r') as f:
50
- html_content = f.read()
51
- elif os.path.exists(tikz_file):
52
- with open(tikz_file, 'r') as f:
53
- html_content = f.read()
54
- else:
55
- html_content = None
56
-
57
- return res, html_content, unique_id
58
-
59
- @spaces.GPU
60
- def process_image(image, task, ocr_type=None, ocr_box=None, ocr_color=None):
61
- demo_html = os.path.join(results_folder, "demo.html")
62
- html_file = os.path.join(results_folder, f"{task.replace(' ', '_').lower()}.html")
63
- tikz_file = os.path.join(results_folder, "tikz.html")
64
-
65
- if task == "Plain Text OCR":
66
- res = model.chat(tokenizer, image, ocr_type='ocr')
67
- return res, None
68
- else:
69
- if task == "Format Text OCR":
70
- res = model.chat(tokenizer, image, ocr_type='format', render=True, save_render_file=demo_html)
71
- elif task == "Fine-grained OCR (Box)":
72
- res = model.chat(tokenizer, image, ocr_type=ocr_type, ocr_box=ocr_box, render=True, save_render_file=demo_html)
73
- elif task == "Fine-grained OCR (Color)":
74
- res = model.chat(tokenizer, image, ocr_type=ocr_type, ocr_color=ocr_color, render=True, save_render_file=demo_html)
75
- elif task == "Multi-crop OCR":
76
- res = model.chat_crop(tokenizer, image, ocr_type='format', render=True, save_render_file=demo_html)
77
- elif task == "Render Formatted OCR":
78
- res = model.chat(tokenizer, image, ocr_type='format', render=True, save_render_file=demo_html)
79
-
80
- if os.path.exists(demo_html):
81
- with open(demo_html, 'r') as f:
82
- html_content = f.read()
83
- elif os.path.exists(html_file):
84
- with open(html_file, 'r') as f:
85
- html_content = f.read()
86
- elif os.path.exists(tikz_file):
87
- with open(tikz_file, 'r') as f:
88
- html_content = f.read()
89
- else:
90
- html_content = None
91
-
92
- return res, html_content