import streamlit as st import requests import json st.title("PDF Extraction App") st.write("Upload a PDF file to extract correct answers and options using the backend service.") # File uploader widget for PDF files uploaded_file = st.file_uploader("Choose a PDF file", type=["pdf"]) if uploaded_file is not None: if st.button("Extract Answers"): with st.spinner("Processing the file, please wait..."): try: # Prepare the file payload files = { "file": (uploaded_file.name, uploaded_file.read(), "application/pdf") } # Make a POST request to the FastAPI endpoint response = requests.post( "https://hammad712-grading.hf.space/extract-answers/", files=files ) # Check for successful response if response.status_code == 200: result = response.json() st.success("Extraction successful!") st.json(result) # Create a download button for the JSON result json_data = json.dumps(result, indent=2) st.download_button( label="Download JSON", data=json_data, file_name="extraction_result.json", mime="application/json" ) else: st.error(f"Error: {response.text}") except Exception as e: st.error(f"An error occurred: {e}")