File size: 856 Bytes
a60f314
8c614dc
f94a1e9
949b422
6ccee3e
949b422
 
 
6ccee3e
7129153
949b422
 
 
 
 
 
 
8c83bdf
f94a1e9
a60f314
 
 
 
7098c0a
 
a60f314
4b1d048
a60f314
 
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
import gradio as gr
import json

def extract_bq_codes_from_json(json_str):
    try:
        data = json.loads(json_str)
    except json.JSONDecodeError:
        return {"error": "Invalid JSON"}

    projecttemplates = data.get("payload", {}).get("projecttemplates", [])
    codes = set()
    for project in projecttemplates:
        details = project.get("projecttemplatedetails", [])
        for detail in details:
            bqcode = detail.get("bqcodelibrary", {}).get("bqcode")
            if bqcode:
                codes.add(bqcode)
    return list(codes)

iface = gr.Interface(
    fn=extract_bq_codes_from_json,
    inputs=gr.Textbox(lines=10, label="JSON Input"),
    outputs=gr.JSON(label="Extracted BQ Codes"),
    title="BQ Code Extractor",
    api_name="predict"  # This names the API endpoint
)

if __name__ == "__main__":
    iface.launch()