File size: 1,227 Bytes
05847c9
2cc093f
05847c9
2cc093f
 
05847c9
2cc093f
 
05847c9
2cc093f
 
 
05847c9
2cc093f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
05847c9
 
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
import streamlit as st
import requests

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)
                else:
                    st.error(f"Error: {response.text}")
            except Exception as e:
                st.error(f"An error occurred: {e}")