Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,36 +1,36 @@
|
|
1 |
import gradio as gr
|
2 |
-
from PIL import Image
|
3 |
import requests
|
4 |
-
import
|
5 |
-
|
6 |
-
# Function to
|
7 |
-
def
|
8 |
-
#
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
api_url = "https://api-inference.huggingface.co/models/Qwen/Qwen-VL"
|
15 |
-
headers = {"Authorization": f"Bearer {HF}"}
|
16 |
|
17 |
-
#
|
18 |
-
|
|
|
|
|
|
|
|
|
19 |
|
20 |
-
#
|
21 |
-
if response.status_code == 200:
|
22 |
-
result = response.json()
|
23 |
-
return result['text'] # Adjust according to the API response format
|
24 |
-
else:
|
25 |
-
return "Error: " + response.text
|
26 |
|
27 |
# Gradio interface
|
28 |
with gr.Blocks() as demo:
|
29 |
-
gr.Markdown("
|
30 |
-
|
31 |
-
|
32 |
-
|
|
|
33 |
|
34 |
-
|
|
|
|
|
35 |
|
|
|
36 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
|
|
2 |
import requests
|
3 |
+
import os
|
4 |
+
|
5 |
+
# Function to query the Qwen model for OCR
|
6 |
+
def query_ocr(image):
|
7 |
+
# Get the Hugging Face access token from secrets
|
8 |
+
hf_token = os.getenv("secret")
|
9 |
+
headers = {"Authorization": f"Bearer {hf_token}"}
|
10 |
+
|
11 |
+
# API endpoint for the model
|
12 |
+
API_URL = "https://api-inference.huggingface.co/models/Qwen/Qwen-VL"
|
|
|
|
|
13 |
|
14 |
+
# Prepare the request
|
15 |
+
files = {"file": image}
|
16 |
+
response = requests.post(API_URL, headers=headers, files=files)
|
17 |
+
|
18 |
+
# Raise an error if the request fails
|
19 |
+
response.raise_for_status()
|
20 |
|
21 |
+
return response.json() # Assuming the model returns a JSON with the extracted text
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
# Gradio interface
|
24 |
with gr.Blocks() as demo:
|
25 |
+
gr.Markdown("# OCR Application using Qwen Model")
|
26 |
+
gr.Markdown("Upload an image to extract text using OCR.")
|
27 |
+
|
28 |
+
image_input = gr.Image(type="file", label="Upload Image")
|
29 |
+
output_text = gr.Textbox(label="Extracted Text", lines=10)
|
30 |
|
31 |
+
submit_btn = gr.Button("Extract Text")
|
32 |
+
|
33 |
+
submit_btn.click(fn=query_ocr, inputs=image_input, outputs=output_text)
|
34 |
|
35 |
+
# Launch the app
|
36 |
demo.launch()
|