Spaces:
Runtime error
Runtime error
File size: 1,097 Bytes
661934e 339e0fe ca56ed5 339e0fe ca56ed5 339e0fe ca56ed5 339e0fe ca56ed5 339e0fe ca56ed5 339e0fe ca56ed5 339e0fe |
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 33 34 35 36 37 |
import gradio as gr
import requests
import os
# Function to query the Qwen model for OCR
def query_ocr(image):
# Get the Hugging Face access token from secrets
hf_token = os.getenv("secret")
headers = {"Authorization": f"Bearer {hf_token}"}
# API endpoint for the model
API_URL = "https://api-inference.huggingface.co/models/Qwen/Qwen-VL"
# Prepare the request
files = {"file": image}
response = requests.post(API_URL, headers=headers, files=files)
# Raise an error if the request fails
response.raise_for_status()
return response.json() # Assuming the model returns a JSON with the extracted text
# Gradio interface
with gr.Blocks() as demo:
gr.Markdown("# OCR Application using Qwen Model")
gr.Markdown("Upload an image to extract text using OCR.")
image_input = gr.Image(type="file", label="Upload Image")
output_text = gr.Textbox(label="Extracted Text", lines=10)
submit_btn = gr.Button("Extract Text")
submit_btn.click(fn=query_ocr, inputs=image_input, outputs=output_text)
# Launch the app
demo.launch()
|