Spaces:
Runtime error
Runtime error
update
Browse files
app.py
CHANGED
|
@@ -5,7 +5,6 @@ from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
|
| 5 |
import matplotlib.pyplot as plt
|
| 6 |
import keras_ocr
|
| 7 |
import cv2
|
| 8 |
-
#from cv2 import INPAINT_NS, inpaint, line, cvtColor, COLOR_BGR2RGB, imwrite
|
| 9 |
import math
|
| 10 |
import numpy as np
|
| 11 |
import gradio as gr
|
|
@@ -13,7 +12,6 @@ import numpy as np
|
|
| 13 |
|
| 14 |
|
| 15 |
#Support for Hindi, Spanish, French, Arabic, Turish, Gailec/Irish, and German
|
| 16 |
-
|
| 17 |
#'hindi':
|
| 18 |
tokenizerhi = AutoTokenizer.from_pretrained("Helsinki-NLP/opus-mt-en-hi")
|
| 19 |
modelhi = AutoModelForSeq2SeqLM.from_pretrained("Helsinki-NLP/opus-mt-en-hi")
|
|
@@ -48,25 +46,18 @@ def choose_language(language):
|
|
| 48 |
#Loading the tokenizers and trained models
|
| 49 |
if language == 'hindi':
|
| 50 |
tokenizer, model = tokenizerhi, modelhi
|
| 51 |
-
#modelnm = "Helsinki-NLP/opus-mt-en-hi"
|
| 52 |
elif language == 'spanish':
|
| 53 |
tokenizer, model = tokenizeres, modeles
|
| 54 |
-
#modelnm = "Helsinki-NLP/opus-mt-en-es"
|
| 55 |
elif language == 'german':
|
| 56 |
tokenizer, model = tokenizerde, modelde
|
| 57 |
-
#modelnm = "Helsinki-NLP/opus-mt-en-de"
|
| 58 |
elif language == 'french':
|
| 59 |
tokenizer, model = tokenizerfr, modelfr
|
| 60 |
-
#modelnm = "Helsinki-NLP/opus-mt-en-fr"
|
| 61 |
elif language == 'turkish':
|
| 62 |
tokenizer, model = tokenizertrk, modeltrk
|
| 63 |
-
#modelnm = "Helsinki-NLP/opus-mt-en-trk"
|
| 64 |
elif language == 'arabic':
|
| 65 |
tokenizer, model = tokenizerar, modelar
|
| 66 |
-
#modelnm = "Helsinki-NLP/opus-mt-en-ar"
|
| 67 |
else:
|
| 68 |
tokenizer, model = tokenizerga, modelga
|
| 69 |
-
#modelnm = "Helsinki-NLP/opus-mt-en-ga"
|
| 70 |
return tokenizer, model
|
| 71 |
|
| 72 |
#Function to translate english text to desired language
|
|
@@ -146,7 +137,7 @@ def translate_image(im, language):
|
|
| 146 |
#Extract text, translate in your language and format it
|
| 147 |
extracted_text = text_extract(im)
|
| 148 |
#font select -- Getting Unicode Text
|
| 149 |
-
title_font = ImageFont.truetype('./arial-unicode-ms.ttf',30)
|
| 150 |
#text to write on image #Example in hindi - Unicode text u"आप जीवन में मिलता हर मौका ले लो, क्योंकि कुछ चीजें केवल एक बार होती हैं. शुभ सुबह"
|
| 151 |
txt = format_text(language,extracted_text)
|
| 152 |
|
|
@@ -158,7 +149,7 @@ def translate_image(im, language):
|
|
| 158 |
|
| 159 |
#Enable writing on image
|
| 160 |
image_editable = ImageDraw.Draw(new_image)
|
| 161 |
-
image_editable.multiline_text((
|
| 162 |
return new_image
|
| 163 |
|
| 164 |
|
|
|
|
| 5 |
import matplotlib.pyplot as plt
|
| 6 |
import keras_ocr
|
| 7 |
import cv2
|
|
|
|
| 8 |
import math
|
| 9 |
import numpy as np
|
| 10 |
import gradio as gr
|
|
|
|
| 12 |
|
| 13 |
|
| 14 |
#Support for Hindi, Spanish, French, Arabic, Turish, Gailec/Irish, and German
|
|
|
|
| 15 |
#'hindi':
|
| 16 |
tokenizerhi = AutoTokenizer.from_pretrained("Helsinki-NLP/opus-mt-en-hi")
|
| 17 |
modelhi = AutoModelForSeq2SeqLM.from_pretrained("Helsinki-NLP/opus-mt-en-hi")
|
|
|
|
| 46 |
#Loading the tokenizers and trained models
|
| 47 |
if language == 'hindi':
|
| 48 |
tokenizer, model = tokenizerhi, modelhi
|
|
|
|
| 49 |
elif language == 'spanish':
|
| 50 |
tokenizer, model = tokenizeres, modeles
|
|
|
|
| 51 |
elif language == 'german':
|
| 52 |
tokenizer, model = tokenizerde, modelde
|
|
|
|
| 53 |
elif language == 'french':
|
| 54 |
tokenizer, model = tokenizerfr, modelfr
|
|
|
|
| 55 |
elif language == 'turkish':
|
| 56 |
tokenizer, model = tokenizertrk, modeltrk
|
|
|
|
| 57 |
elif language == 'arabic':
|
| 58 |
tokenizer, model = tokenizerar, modelar
|
|
|
|
| 59 |
else:
|
| 60 |
tokenizer, model = tokenizerga, modelga
|
|
|
|
| 61 |
return tokenizer, model
|
| 62 |
|
| 63 |
#Function to translate english text to desired language
|
|
|
|
| 137 |
#Extract text, translate in your language and format it
|
| 138 |
extracted_text = text_extract(im)
|
| 139 |
#font select -- Getting Unicode Text
|
| 140 |
+
title_font = ImageFont.truetype('./arial-unicode-ms.ttf',30)
|
| 141 |
#text to write on image #Example in hindi - Unicode text u"आप जीवन में मिलता हर मौका ले लो, क्योंकि कुछ चीजें केवल एक बार होती हैं. शुभ सुबह"
|
| 142 |
txt = format_text(language,extracted_text)
|
| 143 |
|
|
|
|
| 149 |
|
| 150 |
#Enable writing on image
|
| 151 |
image_editable = ImageDraw.Draw(new_image)
|
| 152 |
+
image_editable.multiline_text((10,10), txt,spacing=2, font=title_font, fill= (237, 230, 211)) # Text color e.g. (0, 0, 0)) blacks
|
| 153 |
return new_image
|
| 154 |
|
| 155 |
|