Skip to content

Commit d47e504

Browse files
fix(webui): fix i18n rendering problem
1 parent c9a3e68 commit d47e504

File tree

5 files changed

+487
-55
lines changed

5 files changed

+487
-55
lines changed

requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,5 @@ torch
1515
plotly
1616
pandas
1717
gradio
18-
gradio-i18n
1918
kaleido
2019
pyyaml

webui/app.py

Lines changed: 65 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,29 @@
1-
import json
21
import os
3-
import gradio as gr
2+
import sys
3+
import json
4+
45
import yaml
56

6-
import sys
7+
import gradio as gr
8+
9+
from i18n import Translate, gettext as _
10+
11+
from test_api import test_api_connection
12+
13+
# pylint: disable=wrong-import-position
714
root_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
815
sys.path.append(root_dir)
916

10-
from gradio_i18n import Translate, gettext as _
11-
1217
from graphgen.graphgen import GraphGen
1318
from models import OpenAIModel, Tokenizer, TraverseStrategy
14-
from test_api import test_api_connection
19+
20+
css = """
21+
.center-row {
22+
display: flex;
23+
justify-content: center;
24+
align-items: center;
25+
}
26+
"""
1527

1628
def load_config() -> dict:
1729
with open("config.yaml", "r", encoding='utf-8') as f:
@@ -21,21 +33,6 @@ def save_config(config: dict):
2133
with open("config.yaml", "w", encoding='utf-8') as f:
2234
yaml.dump(config, f)
2335

24-
def load_env() -> dict:
25-
env = {}
26-
if os.path.exists(".env"):
27-
with open(".env", "r", encoding='utf-8') as f:
28-
for line in f:
29-
if "=" in line:
30-
key, value = line.strip().split("=", 1)
31-
env[key] = value
32-
return env
33-
34-
def save_env(env: dict):
35-
with open(".env", "w", encoding='utf-8') as f:
36-
for key, value in env.items():
37-
f.write(f"{key}={value}\n")
38-
3936
def init_graph_gen(config: dict, env: dict) -> GraphGen:
4037
graph_gen = GraphGen()
4138

@@ -126,7 +123,6 @@ def run_graphgen(
126123
"TRAINEE_BASE_URL": trainee_base_url,
127124
"TRAINEE_API_KEY": trainee_api_key
128125
}
129-
save_env(env)
130126

131127
# Initialize GraphGen
132128
graph_gen = init_graph_gen(config, env)
@@ -163,52 +159,71 @@ def run_graphgen(
163159
except Exception as e: # pylint: disable=broad-except
164160
return f"Error occurred: {str(e)}"
165161

166-
config = load_env()
167-
168162
# Create Gradio interface
169-
with gr.Blocks(title="GraphGen Demo") as demo:
170-
lang = gr.Radio(
163+
with gr.Blocks(title="GraphGen Demo", theme=gr.themes.Citrus(), css=css) as demo:
164+
# Header
165+
gr.Image(
166+
value=f"{root_dir}/resources/images/logo.png",
167+
label="GraphGen Banner",
168+
elem_id="banner",
169+
interactive=False,
170+
container=False,
171+
show_download_button=False,
172+
show_fullscreen_button=False
173+
)
174+
lang_btn = gr.Radio(
171175
choices=[
172176
("English", "en"),
173177
("简体中文", "zh"),
174178
],
175179
value="en",
176-
label=_("Language"),
180+
# label=_("Language"),
177181
render=False,
182+
container=False,
183+
elem_classes=["center-row"],
178184
)
185+
186+
gr.HTML("""
187+
<div style="display: flex; gap: 8px; margin-left: auto; align-items: center; justify-content: center;">
188+
<a href="https://github.com/open-sciencelab/GraphGen/releases">
189+
<img src="https://img.shields.io/badge/Version-v0.1.0-blue" alt="Version">
190+
</a>
191+
<a href="https://graphgen-docs.example.com">
192+
<img src="https://img.shields.io/badge/Docs-Latest-brightgreen" alt="Documentation">
193+
</a>
194+
<a href="https://github.com/open-sciencelab/GraphGen">
195+
<img src="https://img.shields.io/github/stars/open-sciencelab/GraphGen?style=social" alt="GitHub Stars">
196+
</a>
197+
<a href="https://arxiv.org/xxxxx">
198+
<img src="https://img.shields.io/badge/arXiv-2401.00001-yellow" alt="arXiv">
199+
</a>
200+
</div>
201+
""")
179202
with Translate(
180-
"translation.yaml",
181-
lang,
203+
"translation.json",
204+
lang_btn,
182205
placeholder_langs=["en", "zh"],
183206
persistant=False, # True to save the language setting in the browser. Requires gradio >= 5.6.0
184207
):
185-
lang.render()
186-
# Header
187-
gr.Image(
188-
value=f"{root_dir}/resources/images/logo.png",
189-
label="GraphGen Banner",
190-
elem_id="banner",
191-
show_label=False,
192-
interactive=False,
193-
)
208+
lang_btn.render()
209+
194210
gr.Markdown(
195-
"""
196-
This is a demo for the [GraphGen](https://github.com/open-sciencelab/GraphGen) project.
197-
GraphGen is a framework for synthetic data generation guided by knowledge graphs.
198-
"""
211+
value = "# " + _("Title") + "\n\n" + \
212+
"### [GraphGen](https://github.com/open-sciencelab/GraphGen) " + _("Intro")
199213
)
214+
215+
200216
with gr.Row():
201217
# Model Configuration Column
202218
with gr.Column(scale=1):
203219
gr.Markdown("### Model Configuration")
204-
synthesizer_model = gr.Textbox(label="Synthesizer Model", value=config.get("SYNTHESIZER_MODEL", ""))
205-
synthesizer_base_url = gr.Textbox(label="Synthesizer Base URL", value=config.get("SYNTHESIZER_BASE_URL", ""))
206-
synthesizer_api_key = gr.Textbox(label="Synthesizer API Key", type="password", value=config.get("SYNTHESIZER_API_KEY", ""))
207-
trainee_model = gr.Textbox(label="Trainee Model", value=config.get("TRAINEE_MODEL", ""))
208-
trainee_base_url = gr.Textbox(label="Trainee Base URL", value=config.get("TRAINEE_BASE_URL", ""))
209-
trainee_api_key = gr.Textbox(label="Trainee API Key", type="password", value=config.get("TRAINEE_API_KEY", ""))
210-
test_connection_btn = gr.Button("Test Connection", variant="primary")
211-
gr.Button("Save Config", variant="primary")
220+
synthesizer_model = gr.Textbox(label="Synthesizer Model", value="")
221+
synthesizer_base_url = gr.Textbox(label="Synthesizer Base URL", value="")
222+
synthesizer_api_key = gr.Textbox(label="Synthesizer API Key", type="password", value="")
223+
trainee_model = gr.Textbox(label="Trainee Model", value="")
224+
trainee_base_url = gr.Textbox(label="Trainee Base URL", value="")
225+
trainee_api_key = gr.Textbox(label="Trainee API Key", type="password", value="")
226+
test_connection_btn = gr.Button("Test Connection")
212227

213228
# Input Configuration Column
214229
with gr.Column(scale=1):

0 commit comments

Comments
 (0)