test / app.py
rawanessam's picture
Update app.py
7098c0a verified
raw
history blame contribute delete
856 Bytes
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()