Spaces:
Sleeping
Sleeping
Toan2004-ai commited on
Commit ·
213de92
1
Parent(s): a7f11a1
add readme config
Browse files
app.py
CHANGED
|
@@ -4,15 +4,16 @@ import json
|
|
| 4 |
import sys
|
| 5 |
|
| 6 |
sys.path.append(".")
|
| 7 |
-
from main import final_process_eme_technical_guided
|
| 8 |
|
| 9 |
def parse_energy_plan(text_input):
|
|
|
|
|
|
|
| 10 |
if not text_input or not text_input.strip():
|
| 11 |
return json.dumps({"error": "Đầu vào không được để trống"}, indent=2)
|
|
|
|
| 12 |
try:
|
| 13 |
try:
|
| 14 |
-
|
| 15 |
-
parsed_json = json.loads(clean_input)
|
| 16 |
if isinstance(parsed_json, dict) and "instances" in parsed_json:
|
| 17 |
raw_payload = parsed_json["instances"][0]["raw_text"]
|
| 18 |
try:
|
|
@@ -21,13 +22,14 @@ def parse_energy_plan(text_input):
|
|
| 21 |
except:
|
| 22 |
final_input = str(raw_payload)
|
| 23 |
else:
|
| 24 |
-
final_input =
|
| 25 |
except json.JSONDecodeError:
|
| 26 |
final_input = text_input
|
| 27 |
|
| 28 |
result = final_process_eme_technical_guided(final_input)
|
| 29 |
result_dict = result.model_dump() if hasattr(result, "model_dump") else result
|
| 30 |
return json.dumps(result_dict, indent=2, ensure_ascii=False)
|
|
|
|
| 31 |
except Exception as e:
|
| 32 |
return json.dumps({"error": str(e)}, indent=2, ensure_ascii=False)
|
| 33 |
|
|
@@ -35,14 +37,14 @@ demo = gr.Interface(
|
|
| 35 |
fn=parse_energy_plan,
|
| 36 |
inputs=gr.Textbox(
|
| 37 |
label="Energy Plan Input",
|
| 38 |
-
placeholder="
|
| 39 |
lines=12
|
| 40 |
),
|
| 41 |
outputs=gr.Code(label="Extracted Schema", language="json"),
|
| 42 |
-
title="
|
| 43 |
-
description="
|
| 44 |
)
|
| 45 |
|
| 46 |
if __name__ == "__main__":
|
| 47 |
-
port = int(os.environ.get("PORT",
|
| 48 |
demo.launch(server_name="0.0.0.0", server_port=port, share=False)
|
|
|
|
| 4 |
import sys
|
| 5 |
|
| 6 |
sys.path.append(".")
|
|
|
|
| 7 |
|
| 8 |
def parse_energy_plan(text_input):
|
| 9 |
+
from main import final_process_eme_technical_guided
|
| 10 |
+
|
| 11 |
if not text_input or not text_input.strip():
|
| 12 |
return json.dumps({"error": "Đầu vào không được để trống"}, indent=2)
|
| 13 |
+
|
| 14 |
try:
|
| 15 |
try:
|
| 16 |
+
parsed_json = json.loads(text_input)
|
|
|
|
| 17 |
if isinstance(parsed_json, dict) and "instances" in parsed_json:
|
| 18 |
raw_payload = parsed_json["instances"][0]["raw_text"]
|
| 19 |
try:
|
|
|
|
| 22 |
except:
|
| 23 |
final_input = str(raw_payload)
|
| 24 |
else:
|
| 25 |
+
final_input = text_input
|
| 26 |
except json.JSONDecodeError:
|
| 27 |
final_input = text_input
|
| 28 |
|
| 29 |
result = final_process_eme_technical_guided(final_input)
|
| 30 |
result_dict = result.model_dump() if hasattr(result, "model_dump") else result
|
| 31 |
return json.dumps(result_dict, indent=2, ensure_ascii=False)
|
| 32 |
+
|
| 33 |
except Exception as e:
|
| 34 |
return json.dumps({"error": str(e)}, indent=2, ensure_ascii=False)
|
| 35 |
|
|
|
|
| 37 |
fn=parse_energy_plan,
|
| 38 |
inputs=gr.Textbox(
|
| 39 |
label="Energy Plan Input",
|
| 40 |
+
placeholder="Dán JSON kế hoạch năng lượng vào đây...",
|
| 41 |
lines=12
|
| 42 |
),
|
| 43 |
outputs=gr.Code(label="Extracted Schema", language="json"),
|
| 44 |
+
title="Volta Energy Plan Parser",
|
| 45 |
+
description="Trích xuất dữ liệu có cấu trúc từ các gói năng lượng Úc."
|
| 46 |
)
|
| 47 |
|
| 48 |
if __name__ == "__main__":
|
| 49 |
+
port = int(os.environ.get("PORT", 7860))
|
| 50 |
demo.launch(server_name="0.0.0.0", server_port=port, share=False)
|