Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import requests
|
| 3 |
+
from PIL import Image
|
| 4 |
+
import io
|
| 5 |
+
import os
|
| 6 |
+
|
| 7 |
+
API_URL = "https://api-inference.huggingface.co/models/Qwen/Qwen-VL"
|
| 8 |
+
|
| 9 |
+
headers = {
|
| 10 |
+
"Authorization": f"Bearer {os.getenv('secret')}"
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
st.title("OCR with Qwen-VL")
|
| 14 |
+
|
| 15 |
+
uploaded_image = st.file_uploader("Upload an image for OCR", type=["jpg", "jpeg", "png"])
|
| 16 |
+
|
| 17 |
+
if uploaded_image is not None:
|
| 18 |
+
image = Image.open(uploaded_image)
|
| 19 |
+
st.image(image, caption="Uploaded Image", use_column_width=True)
|
| 20 |
+
|
| 21 |
+
img_bytes = io.BytesIO()
|
| 22 |
+
image.save(img_bytes, format='PNG')
|
| 23 |
+
img_bytes = img_bytes.getvalue()
|
| 24 |
+
|
| 25 |
+
st.write("Processing the image...")
|
| 26 |
+
response = requests.post(API_URL, headers=headers, files={"file": img_bytes})
|
| 27 |
+
|
| 28 |
+
if response.status_code == 200:
|
| 29 |
+
result = response.json()
|
| 30 |
+
st.write("Extracted Text:")
|
| 31 |
+
st.text(result.get("generated_text", "No text found in the image"))
|
| 32 |
+
else:
|
| 33 |
+
st.write(f"Error: {response.status_code} - {response.text}")
|