Update app.py
Browse files
app.py
CHANGED
|
@@ -67,13 +67,11 @@ def load_file(file):
|
|
| 67 |
|
| 68 |
try:
|
| 69 |
with open(file.name, 'r', encoding='utf-8') as f:
|
| 70 |
-
|
| 71 |
-
return content
|
| 72 |
except:
|
| 73 |
try:
|
| 74 |
with open(file.name, 'r', encoding='latin-1') as f:
|
| 75 |
-
|
| 76 |
-
return content
|
| 77 |
except Exception as e:
|
| 78 |
return f"Error reading file: {str(e)}"
|
| 79 |
|
|
@@ -143,6 +141,23 @@ custom_css = """
|
|
| 143 |
}
|
| 144 |
"""
|
| 145 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 146 |
with gr.Blocks(css=custom_css, theme=gr.themes.Default()) as demo:
|
| 147 |
|
| 148 |
gr.HTML("<div style='height: 20px'></div>")
|
|
@@ -168,15 +183,6 @@ with gr.Blocks(css=custom_css, theme=gr.themes.Default()) as demo:
|
|
| 168 |
container=False,
|
| 169 |
elem_classes="text-area"
|
| 170 |
)
|
| 171 |
-
|
| 172 |
-
with gr.Row(visible=True):
|
| 173 |
-
file_input = gr.File(
|
| 174 |
-
label="",
|
| 175 |
-
file_types=[".txt"],
|
| 176 |
-
type="filepath",
|
| 177 |
-
scale=1,
|
| 178 |
-
container=False
|
| 179 |
-
)
|
| 180 |
|
| 181 |
with gr.Column(scale=0, min_width=100):
|
| 182 |
with gr.Row(elem_classes="swap-container"):
|
|
@@ -213,7 +219,7 @@ with gr.Blocks(css=custom_css, theme=gr.themes.Default()) as demo:
|
|
| 213 |
with gr.Accordion("Example Sentences", open=True):
|
| 214 |
with gr.Row():
|
| 215 |
example_text = gr.Textbox(
|
| 216 |
-
value="
|
| 217 |
label="",
|
| 218 |
lines=3,
|
| 219 |
max_lines=5,
|
|
@@ -222,24 +228,46 @@ with gr.Blocks(css=custom_css, theme=gr.themes.Default()) as demo:
|
|
| 222 |
use_example_btn = gr.Button("Use This Example →", variant="primary", size="sm")
|
| 223 |
|
| 224 |
with gr.Row():
|
| 225 |
-
gr.Button("Drilling
|
| 226 |
-
lambda: "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 227 |
outputs=example_text
|
| 228 |
)
|
| 229 |
-
gr.Button("
|
| 230 |
-
lambda: "
|
| 231 |
outputs=example_text
|
| 232 |
)
|
| 233 |
-
gr.Button("
|
| 234 |
-
lambda: "
|
| 235 |
outputs=example_text
|
| 236 |
)
|
| 237 |
-
gr.Button("
|
| 238 |
-
lambda: "
|
| 239 |
outputs=example_text
|
| 240 |
)
|
| 241 |
-
gr.Button("Safety
|
| 242 |
-
lambda: "
|
| 243 |
outputs=example_text
|
| 244 |
)
|
| 245 |
|
|
@@ -249,6 +277,13 @@ with gr.Blocks(css=custom_css, theme=gr.themes.Default()) as demo:
|
|
| 249 |
outputs=input_text
|
| 250 |
)
|
| 251 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 252 |
input_text.change(
|
| 253 |
fn=translate,
|
| 254 |
inputs=[input_text, source_lang, target_lang],
|
|
|
|
| 67 |
|
| 68 |
try:
|
| 69 |
with open(file.name, 'r', encoding='utf-8') as f:
|
| 70 |
+
return f.read()
|
|
|
|
| 71 |
except:
|
| 72 |
try:
|
| 73 |
with open(file.name, 'r', encoding='latin-1') as f:
|
| 74 |
+
return f.read()
|
|
|
|
| 75 |
except Exception as e:
|
| 76 |
return f"Error reading file: {str(e)}"
|
| 77 |
|
|
|
|
| 141 |
}
|
| 142 |
"""
|
| 143 |
|
| 144 |
+
EXAMPLES = {
|
| 145 |
+
"drilling_short": "Mud weight adjusted to 1.82 specific gravity at 3,247 meters depth.",
|
| 146 |
+
"drilling_long": "The drilling operation at well site A-15 encountered unexpected high-pressure zones at 3,247 meters depth, requiring immediate adjustment of mud weight from 1.65 to 1.82 specific gravity to maintain wellbore stability and prevent potential kicks.",
|
| 147 |
+
|
| 148 |
+
"reservoir_short": "Permeability is 250 millidarcy with 22 percent porosity.",
|
| 149 |
+
"reservoir_long": "Reservoaret viser utmerket permeabilitet på 250 millidarcy og porøsitet på 22 prosent basert på kjerneanalyse, noe som indikerer betydelig hydrokarbonpotensial med estimert oljemetning på 65 prosent.",
|
| 150 |
+
|
| 151 |
+
"subsea_short": "Christmas tree rated for 10,000 psi working pressure.",
|
| 152 |
+
"subsea_long": "The subsea production system consists of a vertical Christmas tree rated for 10,000 psi working pressure and 150 degrees Celsius temperature, equipped with redundant safety features including automatic shutdown valves and real-time pressure monitoring systems.",
|
| 153 |
+
|
| 154 |
+
"seismic_short": "Structural trap area estimated at 12 square kilometers.",
|
| 155 |
+
"seismic_long": "Seismiske data bekrefter tilstedeværelsen av en strukturell felle med estimert areal på 12 kvadratkilometer, og produktivitetstester viser stabilisert oljeproduksjon på 3,400 fat per dag ved optimaliseringstrykk på 2,100 psi.",
|
| 156 |
+
|
| 157 |
+
"safety_short": "H2S training required before site access.",
|
| 158 |
+
"safety_long": "Emergency response procedures require all personnel to complete H2S safety training before site access, with breathing apparatus and wind indicators positioned at designated muster points, and immediate evacuation protocols activated when gas detection exceeds 10 ppm concentration levels."
|
| 159 |
+
}
|
| 160 |
+
|
| 161 |
with gr.Blocks(css=custom_css, theme=gr.themes.Default()) as demo:
|
| 162 |
|
| 163 |
gr.HTML("<div style='height: 20px'></div>")
|
|
|
|
| 183 |
container=False,
|
| 184 |
elem_classes="text-area"
|
| 185 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 186 |
|
| 187 |
with gr.Column(scale=0, min_width=100):
|
| 188 |
with gr.Row(elem_classes="swap-container"):
|
|
|
|
| 219 |
with gr.Accordion("Example Sentences", open=True):
|
| 220 |
with gr.Row():
|
| 221 |
example_text = gr.Textbox(
|
| 222 |
+
value=EXAMPLES["drilling_short"],
|
| 223 |
label="",
|
| 224 |
lines=3,
|
| 225 |
max_lines=5,
|
|
|
|
| 228 |
use_example_btn = gr.Button("Use This Example →", variant="primary", size="sm")
|
| 229 |
|
| 230 |
with gr.Row():
|
| 231 |
+
gr.Button("Drilling (Short)", size="sm").click(
|
| 232 |
+
lambda: EXAMPLES["drilling_short"],
|
| 233 |
+
outputs=example_text
|
| 234 |
+
)
|
| 235 |
+
gr.Button("Drilling (Long)", size="sm").click(
|
| 236 |
+
lambda: EXAMPLES["drilling_long"],
|
| 237 |
+
outputs=example_text
|
| 238 |
+
)
|
| 239 |
+
gr.Button("Reservoir (Short)", size="sm").click(
|
| 240 |
+
lambda: EXAMPLES["reservoir_short"],
|
| 241 |
+
outputs=example_text
|
| 242 |
+
)
|
| 243 |
+
gr.Button("Reservoir (Long)", size="sm").click(
|
| 244 |
+
lambda: EXAMPLES["reservoir_long"],
|
| 245 |
+
outputs=example_text
|
| 246 |
+
)
|
| 247 |
+
gr.Button("Subsea (Short)", size="sm").click(
|
| 248 |
+
lambda: EXAMPLES["subsea_short"],
|
| 249 |
+
outputs=example_text
|
| 250 |
+
)
|
| 251 |
+
|
| 252 |
+
with gr.Row():
|
| 253 |
+
gr.Button("Subsea (Long)", size="sm").click(
|
| 254 |
+
lambda: EXAMPLES["subsea_long"],
|
| 255 |
outputs=example_text
|
| 256 |
)
|
| 257 |
+
gr.Button("Seismic (Short)", size="sm").click(
|
| 258 |
+
lambda: EXAMPLES["seismic_short"],
|
| 259 |
outputs=example_text
|
| 260 |
)
|
| 261 |
+
gr.Button("Seismic (Long)", size="sm").click(
|
| 262 |
+
lambda: EXAMPLES["seismic_long"],
|
| 263 |
outputs=example_text
|
| 264 |
)
|
| 265 |
+
gr.Button("Safety (Short)", size="sm").click(
|
| 266 |
+
lambda: EXAMPLES["safety_short"],
|
| 267 |
outputs=example_text
|
| 268 |
)
|
| 269 |
+
gr.Button("Safety (Long)", size="sm").click(
|
| 270 |
+
lambda: EXAMPLES["safety_long"],
|
| 271 |
outputs=example_text
|
| 272 |
)
|
| 273 |
|
|
|
|
| 277 |
outputs=input_text
|
| 278 |
)
|
| 279 |
|
| 280 |
+
with gr.Accordion("Upload Text File", open=False):
|
| 281 |
+
file_input = gr.File(
|
| 282 |
+
label="Upload a .txt file to translate",
|
| 283 |
+
file_types=[".txt"],
|
| 284 |
+
type="filepath"
|
| 285 |
+
)
|
| 286 |
+
|
| 287 |
input_text.change(
|
| 288 |
fn=translate,
|
| 289 |
inputs=[input_text, source_lang, target_lang],
|