add theme
Browse files
app.py
CHANGED
|
@@ -13,14 +13,54 @@ user_input:
|
|
| 13 |
Returns:
|
| 14 |
string: translated string of text
|
| 15 |
"""
|
| 16 |
-
|
|
|
|
| 17 |
import gradio as gr
|
|
|
|
|
|
|
| 18 |
import argparse
|
| 19 |
|
| 20 |
import langid
|
| 21 |
from transformers import pipeline
|
| 22 |
|
| 23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
def detect_lang(article, target_lang):
|
| 25 |
"""
|
| 26 |
Language Detection using library langid
|
|
@@ -68,15 +108,18 @@ def opus_trans(article, target_language):
|
|
| 68 |
return translated
|
| 69 |
|
| 70 |
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
[
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
|
|
|
|
|
|
|
|
|
| 81 |
|
| 82 |
-
|
|
|
|
| 13 |
Returns:
|
| 14 |
string: translated string of text
|
| 15 |
"""
|
| 16 |
+
from __future__ import annotations
|
| 17 |
+
from typing import Iterable
|
| 18 |
import gradio as gr
|
| 19 |
+
from gradio.themes.base import Base
|
| 20 |
+
from gradio.themes.utils import colors, fonts, sizes
|
| 21 |
import argparse
|
| 22 |
|
| 23 |
import langid
|
| 24 |
from transformers import pipeline
|
| 25 |
|
| 26 |
|
| 27 |
+
class myTheme(Base):
|
| 28 |
+
def __init__(
|
| 29 |
+
self,
|
| 30 |
+
*,
|
| 31 |
+
primary_hue: colors.Color | str = colors.emerald,
|
| 32 |
+
secondary_hue: colors.Color | str = colors.blue,
|
| 33 |
+
neutral_hue: colors.Color | str = colors.gray,
|
| 34 |
+
spacing_size: sizes.Size | str = sizes.spacing_md,
|
| 35 |
+
radius_size: sizes.Size | str = sizes.radius_md,
|
| 36 |
+
text_size: sizes.Size | str = sizes.text_lg,
|
| 37 |
+
font: fonts.Font
|
| 38 |
+
| str
|
| 39 |
+
| Iterable[fonts.Font | str] = (
|
| 40 |
+
fonts.GoogleFont("Quicksand"),
|
| 41 |
+
"ui-sans-serif",
|
| 42 |
+
"sans-serif",
|
| 43 |
+
),
|
| 44 |
+
font_mono: fonts.Font
|
| 45 |
+
| str
|
| 46 |
+
| Iterable[fonts.Font | str] = (
|
| 47 |
+
fonts.GoogleFont("IBM Plex Mono"),
|
| 48 |
+
"ui-monospace",
|
| 49 |
+
"monospace",
|
| 50 |
+
),
|
| 51 |
+
):
|
| 52 |
+
super().__init__(
|
| 53 |
+
primary_hue=primary_hue,
|
| 54 |
+
secondary_hue=secondary_hue,
|
| 55 |
+
neutral_hue=neutral_hue,
|
| 56 |
+
spacing_size=spacing_size,
|
| 57 |
+
radius_size=radius_size,
|
| 58 |
+
text_size=text_size,
|
| 59 |
+
font=font,
|
| 60 |
+
font_mono=font_mono,
|
| 61 |
+
)
|
| 62 |
+
|
| 63 |
+
|
| 64 |
def detect_lang(article, target_lang):
|
| 65 |
"""
|
| 66 |
Language Detection using library langid
|
|
|
|
| 108 |
return translated
|
| 109 |
|
| 110 |
|
| 111 |
+
myTheme = myTheme()
|
| 112 |
+
|
| 113 |
+
with gr.Blocks(theme=myTheme) as demo:
|
| 114 |
+
article = gr.Textbox()
|
| 115 |
+
lang_select = gr.Radio(["English", "Chinese"])
|
| 116 |
+
translate = gr.Interface(
|
| 117 |
+
opus_trans,
|
| 118 |
+
[
|
| 119 |
+
article,
|
| 120 |
+
lang_select,
|
| 121 |
+
],
|
| 122 |
+
outputs=gr.Textbox(),
|
| 123 |
+
)
|
| 124 |
|
| 125 |
+
demo.launch()
|