File size: 1,861 Bytes
d67e63b
 
76ac40e
d67e63b
 
4eecb7b
 
d67e63b
8f4aedc
213de92
d67e63b
76ac40e
d67e63b
44bdf9e
 
 
 
 
 
d4e9165
44bdf9e
d67e63b
76ac40e
d4e9165
4eecb7b
d67e63b
d4e9165
44bdf9e
 
d67e63b
3876905
d67e63b
213de92
d67e63b
 
 
 
 
8f4aedc
3876905
213de92
a712270
d67e63b
 
 
a712270
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import gradio as gr
import json
import os

def parse_energy_plan(text_input):
    from engine import final_process_eme_technical_guided
    
    if not text_input or not text_input.strip():
        return json.dumps({"error": "Input cannot be empty"}, indent=2)
        
    try:
        final_input = text_input
        try:
            # Thêm dấu ngoặc nếu thiếu
            stripped = text_input.strip()
            if not stripped.startswith("{") and not stripped.startswith("["):
                stripped = "{" + stripped + "}"
            
            clean_input = stripped.replace("None", "null").replace("True", "true").replace("False", "false")
            parsed_json = json.loads(clean_input)
            
            if isinstance(parsed_json, dict) and "instances" in parsed_json:
                final_input = parsed_json["instances"][0].get("raw_text", text_input)
            else:
                final_input = json.dumps(parsed_json)
        except json.JSONDecodeError:
            final_input = text_input
        
        print(f"=== final_input preview: {final_input[:200]}")
        result = final_process_eme_technical_guided(final_input)
        result_dict = result.model_dump() if hasattr(result, "model_dump") else result
        return json.dumps(result_dict, indent=2, ensure_ascii=False)
        
    except Exception as e:
        return json.dumps({"error": str(e)}, indent=2, ensure_ascii=False)

demo = gr.Interface(
    fn=parse_energy_plan,
    inputs=gr.Textbox(label="Energy Plan Input", placeholder="Paste the energy plan JSON here...", lines=10),
    outputs=gr.Code(label="Extracted Schema", language="json"),
    title="Volta Energy Plan Parser",
    description="Energy Data Extraction Testing Interface"
)

if __name__ == "__main__":
    demo.launch(server_name="0.0.0.0", server_port=8080, ssr_mode=False)