Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import requests
|
| 3 |
+
|
| 4 |
+
st.title("OCR Extraction Client")
|
| 5 |
+
|
| 6 |
+
st.write(
|
| 7 |
+
"""
|
| 8 |
+
This app lets you upload a PDF or image file. The file is sent to a FastAPI endpoint for OCR extraction,
|
| 9 |
+
and then the extracted text is returned as a Markdown file.
|
| 10 |
+
"""
|
| 11 |
+
)
|
| 12 |
+
|
| 13 |
+
uploaded_file = st.file_uploader("Upload a PDF or image file", type=["pdf", "png", "jpg", "jpeg", "webp"])
|
| 14 |
+
|
| 15 |
+
if uploaded_file is not None:
|
| 16 |
+
st.info(f"Processing file: **{uploaded_file.name}**")
|
| 17 |
+
with st.spinner("Sending file to OCR service..."):
|
| 18 |
+
# Prepare the file payload.
|
| 19 |
+
files = {"file": (uploaded_file.name, uploaded_file, uploaded_file.type)}
|
| 20 |
+
|
| 21 |
+
# Replace the URL below with your FastAPI endpoint URL.
|
| 22 |
+
api_url = "https://hammad712-urdu-ocr-app.hf.space/upload"
|
| 23 |
+
response = requests.post(api_url, files=files)
|
| 24 |
+
|
| 25 |
+
if response.status_code == 200:
|
| 26 |
+
st.success("OCR extraction complete!")
|
| 27 |
+
|
| 28 |
+
# Get the returned Markdown content.
|
| 29 |
+
md_content = response.content.decode("utf-8")
|
| 30 |
+
|
| 31 |
+
st.markdown("### Extracted Markdown Text")
|
| 32 |
+
st.markdown(md_content)
|
| 33 |
+
|
| 34 |
+
st.download_button(
|
| 35 |
+
label="Download Markdown File",
|
| 36 |
+
data=md_content,
|
| 37 |
+
file_name="output.md",
|
| 38 |
+
mime="text/markdown"
|
| 39 |
+
)
|
| 40 |
+
else:
|
| 41 |
+
st.error(f"Error: {response.status_code} {response.text}")
|