Spaces:
Sleeping
Sleeping
File size: 1,554 Bytes
9149d7f d095c85 9149d7f d095c85 9149d7f | 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 | import gradio as gr
import json
def extract_answer(json_file, query):
try:
with open(json_file.name, "r", encoding="utf-8") as f:
data = json.load(f)
results = []
for section in data.get("summary", []):
heading = section.get("heading", "")
bullets = section.get("bullets", [])
for bullet in bullets:
if query.lower() in bullet.lower() or query.lower() in heading.lower():
results.append(f"🔸{heading}: {bullet}")
if not results:
return "No relevant content found."
return "\n\n".join(results)
except Exception as e:
return f"Error reading file: {str(e)}"
with gr.Blocks() as demo:
gr.Markdown("🔍 **Adobe Hackathon - Round 1B Summarizer UI**")
gr.Markdown("Upload your generated summary JSON and enter a question to view top relevant content from the PDF.")
with gr.Row():
file_input = gr.File(label="Upload Round 1B Summary JSON", file_types=[".json"])
output_box = gr.Textbox(label="Top Relevant Results", lines=10)
query_input = gr.Textbox(label="Enter Persona-Based Query", placeholder="e.g., ER DIAGRAM")
clear_btn = gr.Button("Clear")
submit_btn = gr.Button("Submit")
def clear_inputs():
return None, "", ""
submit_btn.click(fn=extract_answer, inputs=[file_input, query_input], outputs=output_box)
clear_btn.click(fn=clear_inputs, inputs=[], outputs=[file_input, query_input, output_box])
demo.launch()
|