Luis J Camargo commited on
Commit
97cd2f8
·
1 Parent(s): 2886d21

ui beautify

Browse files
Files changed (1) hide show
  1. app.py +26 -14
app.py CHANGED
@@ -109,17 +109,23 @@ def inference(img):
109
  use_cache=False # Cache helps speed on CPU significantly
110
  )
111
 
112
- # Threading is REQUIRED for streaming
113
- # The model generates in a separate thread, while the main thread
114
- # yields from the streamer iterator.
115
  thread = Thread(target=model.generate, kwargs=generation_kwargs)
116
  thread.start()
117
 
118
  generated_text = ""
 
119
  for new_text in streamer:
120
- generated_text += new_text
 
 
 
 
121
  # Yielding here updates the Gradio textbox in real-time
122
- yield generated_text
 
 
 
123
 
124
  except Exception as e:
125
  import traceback
@@ -138,10 +144,13 @@ description = '''
138
  This model represents a **world first in tech access and linguistic rights**, specifically trained to recognize
139
  the diverse character and glyph repertoire of Mexico's 68 indigenous languages.
140
 
141
- **How to use:** Simply upload an image containing text in any Mexican indigenous language.
142
- **Note:** Running on CPU. Streaming is enabled so you can see progress immediately.
 
 
143
 
144
- 🔗 [PaddleOCR Documentation](https://github.com/PaddlePaddle/PaddleOCR)
 
145
  '''
146
 
147
  examples = [
@@ -166,11 +175,14 @@ example_labels = """
166
  | lac.jpg | Lacandon | wa quin chen u'yicob a t'ʌnex, wa yʌn in wu'yicob a ba' cu ya'aric C'uj? Tin t'ʌn, mʌ' in wu'yicob a t'ʌnex, yʌn in wu'yicob a ba' cu ya'aric C'uj. Yʌn in man in wa'aricob a ba' caj in wirajob yejer a ba' caj in wu'yajob ―baxuc tu ya'araj Pedro ti' u jach ts'urirob. Jeroj tune', chich t'ʌn Pedro yejer Juan ten u jach ts'urirob u winiquirob judío, caj ts'oquij caj cha'b u binob ten u jach ts'urirob. |
167
  """
168
 
169
- css = ".output_image, .input_image {height: 40rem !important; width: 100% !important;} .output_markdown {min-height: 30rem !important;}"
170
-
171
- # Note: We replaced gr.Interface with gr.Blocks or used the generator compatible interface
172
- # But standard Interface supports generators in newer Gradio versions.
173
- # Just ensuring concurrency_limit is set.
 
 
 
174
 
175
  demo = gr.Interface(
176
  fn=inference,
@@ -208,4 +220,4 @@ demo = gr.Interface(
208
  )
209
 
210
  if __name__ == "__main__":
211
- demo.queue().launch()
 
109
  use_cache=False # Cache helps speed on CPU significantly
110
  )
111
 
112
+ logger.info("Starting model generation...")
 
 
113
  thread = Thread(target=model.generate, kwargs=generation_kwargs)
114
  thread.start()
115
 
116
  generated_text = ""
117
+ status_indicator = " **[...Processing]** ⏳"
118
  for new_text in streamer:
119
+ if generated_text == "":
120
+ # Todo: remove the removal of first character when the model is fixed
121
+ generated_text = new_text[1:]
122
+ else:
123
+ generated_text += new_text
124
  # Yielding here updates the Gradio textbox in real-time
125
+ logger.info("yielding: " + generated_text)
126
+ yield generated_text + status_indicator
127
+
128
+ yield generated_text
129
 
130
  except Exception as e:
131
  import traceback
 
144
  This model represents a **world first in tech access and linguistic rights**, specifically trained to recognize
145
  the diverse character and glyph repertoire of Mexico's 68 indigenous languages.
146
 
147
+ **How to use:** Simply upload an image containing text in any Mexican indigenous language, and the model will
148
+ detect and recognize the text.
149
+
150
+ ### Warning: as this free demonstrator space uses only CPU, even small image could take up to 5 minutes, so be patient.
151
 
152
+ 🔗 [TachiwinOCR Model](https://huggingface.co/tachiwin/PaddleOCR-VL-Tachiwin-BF16)
153
+ 🔗 [TachiwinOCR Training Code](https://github.com/ljcamargo/tachiwin_paddleocrvl_finetuning)
154
  '''
155
 
156
  examples = [
 
175
  | lac.jpg | Lacandon | wa quin chen u'yicob a t'ʌnex, wa yʌn in wu'yicob a ba' cu ya'aric C'uj? Tin t'ʌn, mʌ' in wu'yicob a t'ʌnex, yʌn in wu'yicob a ba' cu ya'aric C'uj. Yʌn in man in wa'aricob a ba' caj in wirajob yejer a ba' caj in wu'yajob ―baxuc tu ya'araj Pedro ti' u jach ts'urirob. Jeroj tune', chich t'ʌn Pedro yejer Juan ten u jach ts'urirob u winiquirob judío, caj ts'oquij caj cha'b u binob ten u jach ts'urirob. |
176
  """
177
 
178
+ css = """
179
+ .output_image, .input_image {height: 40rem !important; width: 100% !important;}
180
+ .output_markdown {min-height: 30rem !important;}
181
+ .output_markdown p, .output_markdown {
182
+ font-size: 1.3rem !important;
183
+ line-height: 1.6 !important;
184
+ }
185
+ """
186
 
187
  demo = gr.Interface(
188
  fn=inference,
 
220
  )
221
 
222
  if __name__ == "__main__":
223
+ demo.queue().launch(debug=True)