Spaces:
Sleeping
Sleeping
Download app.py from ritk/AdobeHackathon: direct link, hf CLI and curl.
- Browser
- Download file 1.55 kB
-
https://huggingface.co/spaces/ritk/AdobeHackathon/resolve/main/app.py
- Command line
-
hf download hf://spaces/ritk/AdobeHackathon/app.py
-
curl -L -o app.py https://huggingface.co/spaces/ritk/AdobeHackathon/resolve/main/app.py
1.55 kB
| 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() | |