NightPrince commited on
Commit
cc7032e
·
verified ·
1 Parent(s): 24418b5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -33
app.py CHANGED
@@ -3,7 +3,6 @@ import tensorflow as tf
3
  import numpy as np
4
  from tensorflow.keras.preprocessing.sequence import pad_sequences
5
  import json
6
- import os
7
 
8
  # Initialize global variables
9
  model = None
@@ -14,7 +13,7 @@ def load_model_artifacts():
14
  """Load model and tokenizer artifacts for Arabic text generation."""
15
  global model, tokenizer, max_len_seq
16
 
17
- # Paths for files in Kaggle
18
  model_path = 'model.h5'
19
  tokenizer_path = 'tokenizer.json'
20
  config_path = 'config.json'
@@ -78,7 +77,7 @@ texts = {
78
  }
79
  }
80
 
81
- def get_interface(language="ar"):
82
  """Create a Gradio interface based on the selected language."""
83
  lang_texts = texts[language]
84
  rtl = "rtl" if language == "ar" else "ltr"
@@ -86,12 +85,6 @@ def get_interface(language="ar"):
86
 
87
  return gr.Interface(
88
  fn=generate_arabic_text,
89
- outputs=gr.Textbox(
90
- label=lang_texts["output_label"],
91
- elem_id="output-textbox"
92
- ),
93
- title=lang_texts["title"],
94
- description=lang_texts["description"],
95
  inputs=[
96
  gr.Textbox(
97
  label=lang_texts["input_label"],
@@ -107,7 +100,13 @@ def get_interface(language="ar"):
107
  label=lang_texts["num_words_label"]
108
  )
109
  ],
110
- theme=gr.themes.Default(primary_hue="blue", secondary_hue="green", neutral_hue="slate"),
 
 
 
 
 
 
111
  css=f"""
112
  #input-textbox textarea {{
113
  text-align: {alignment};
@@ -124,36 +123,20 @@ def get_interface(language="ar"):
124
  }}
125
 
126
  body {{
127
- background: linear-gradient(to right, #4facfe, #00f2fe);
128
  font-family: 'Cairo', sans-serif;
129
- }}
130
-
131
- .gr-button {{
132
- background: #007bff;
133
- color: white;
134
- border-radius: 8px;
135
- font-weight: bold;
136
  }}
137
  """
138
  )
139
 
140
- # Language toggle function
141
  def toggle_language(lang):
142
  global iface
143
- iface = get_interface(language=lang)
144
- iface.launch(share=True)
145
 
146
- # Initial interface
147
- iface = get_interface(language="ar")
148
 
149
- # Launch the app
150
  if __name__ == "__main__":
151
- with gr.Blocks() as demo:
152
- gr.Markdown("# اختر اللغة | Choose Language")
153
- gr.Row([
154
- gr.Button("العربية").click(fn=lambda: toggle_language("ar")),
155
- gr.Button("English").click(fn=lambda: toggle_language("en"))
156
- ])
157
- demo.append(iface)
158
-
159
- demo.launch()
 
3
  import numpy as np
4
  from tensorflow.keras.preprocessing.sequence import pad_sequences
5
  import json
 
6
 
7
  # Initialize global variables
8
  model = None
 
13
  """Load model and tokenizer artifacts for Arabic text generation."""
14
  global model, tokenizer, max_len_seq
15
 
16
+ # Paths for files in the current directory
17
  model_path = 'model.h5'
18
  tokenizer_path = 'tokenizer.json'
19
  config_path = 'config.json'
 
77
  }
78
  }
79
 
80
+ def create_interface(language="ar"):
81
  """Create a Gradio interface based on the selected language."""
82
  lang_texts = texts[language]
83
  rtl = "rtl" if language == "ar" else "ltr"
 
85
 
86
  return gr.Interface(
87
  fn=generate_arabic_text,
 
 
 
 
 
 
88
  inputs=[
89
  gr.Textbox(
90
  label=lang_texts["input_label"],
 
100
  label=lang_texts["num_words_label"]
101
  )
102
  ],
103
+ outputs=gr.Textbox(
104
+ label=lang_texts["output_label"],
105
+ elem_id="output-textbox"
106
+ ),
107
+ title=lang_texts["title"],
108
+ description=lang_texts["description"],
109
+ theme=gr.themes.Default(primary_hue="blue"),
110
  css=f"""
111
  #input-textbox textarea {{
112
  text-align: {alignment};
 
123
  }}
124
 
125
  body {{
 
126
  font-family: 'Cairo', sans-serif;
127
+ background: linear-gradient(to right, #4facfe, #00f2fe);
 
 
 
 
 
 
128
  }}
129
  """
130
  )
131
 
132
+ # Language selection interface
133
  def toggle_language(lang):
134
  global iface
135
+ iface = create_interface(language=lang)
136
+ iface.launch()
137
 
138
+ # Default to Arabic interface
139
+ iface = create_interface(language="ar")
140
 
 
141
  if __name__ == "__main__":
142
+ iface.launch()