Kabilash10's picture
Update app.py
ca56ed5 verified
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()