Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- app.py +34 -0
- requirements.txt +2 -0
app.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import time
|
| 3 |
+
from deep_translator import GoogleTranslator
|
| 4 |
+
|
| 5 |
+
def tarjim(text, choice, progress = gr.Progress()):
|
| 6 |
+
progress(0, desc="Tarjima qilish boshlandi. Iltimos ozgina vaqt kuting...")
|
| 7 |
+
try:
|
| 8 |
+
if text and choice:
|
| 9 |
+
support_languages = GoogleTranslator().get_supported_languages(as_dict=True)
|
| 10 |
+
for i in progress.tqdm(range(100)):
|
| 11 |
+
time.sleep(0.01)
|
| 12 |
+
return GoogleTranslator(source='auto',target=support_languages[choice]).translate(text.replace('\n', ' '))
|
| 13 |
+
else:
|
| 14 |
+
return gr.Info("Kiritish maydoni bo'sh bo'lmasligi kerak %s" % text)
|
| 15 |
+
except Exception as e:
|
| 16 |
+
return gr.Error("Xatolik nomi: %s" % e)
|
| 17 |
+
|
| 18 |
+
with gr.Blocks() as demo:
|
| 19 |
+
gr.Markdown(
|
| 20 |
+
"""
|
| 21 |
+
# Tezkor tarjima!
|
| 22 |
+
Ma'lumotlarni tezkor tajima qilish uchun kiritish maydonini bo'sh qoldirmang.
|
| 23 |
+
""")
|
| 24 |
+
with gr.Row():
|
| 25 |
+
with gr.Column():
|
| 26 |
+
tanlash = gr.Dropdown(label='Tilni tanlang', choices=GoogleTranslator().get_supported_languages(), value='uzbek')
|
| 27 |
+
inp = gr.Textbox(label='kirish qismi', placeholder="Tarjima mantnini kiriting..." ,autofocus=True)
|
| 28 |
+
with gr.Column():
|
| 29 |
+
out = gr.Textbox(label='Natija', show_copy_button=True)
|
| 30 |
+
theme=gr.themes.Base()
|
| 31 |
+
inp.change(tarjim, [inp, tanlash], out)
|
| 32 |
+
|
| 33 |
+
if __name__ == "__main__":
|
| 34 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
deep-translator
|