i have this code and i want a gradio gui for this , i created one but it showing error in output:
import gradio as gr
import time
from azure.cognitiveservices.vision.computervision import ComputerVisionClient
from azure.cognitiveservices.vision.computervision.models import OperationStatusCodes
from msrest.authentication import CognitiveServicesCredentials
Replace ‘your_subscription_key’ and ‘your_endpoint’ with your actual subscription key and endpoint
subscription_key =
endpoint =
Create a Computer Vision client
computervision_client = ComputerVisionClient(endpoint, CognitiveServicesCredentials(subscription_key))
def detect_text_in_image(image):
# Open the image file in binary mode
with open(image.name, “rb”) as image_stream:
# Call API with the image stream
read_response = computervision_client.read_in_stream(image_stream, raw=True)
# Get the operation location (URL with an ID at the end) from the response
read_operation_location = read_response.headers["Operation-Location"]
# Grab the ID from the URL
operation_id = read_operation_location.split("/")[-1]
# Call the "GET" API and wait for it to retrieve the results
while True:
read_result = computervision_client.get_read_result(operation_id)
if read_result.status not in ['notStarted', 'running']:
break
time.sleep(1)
# Collect the detected text
detected_text = ""
if read_result.status == OperationStatusCodes.succeeded:
for text_result in read_result.analyze_result.read_results:
for line in text_result.lines:
detected_text += line.text + "n"
return detected_text
`inputs = gr.components.Image()
outputs = gr.Textbox(label=”Detected Number”)
gr.Interface(fn=detect_text_in_image, inputs=inputs, outputs=outputs).launch();
can anyone help me with this?? I want a GUI for this code in python??
Cohesive Gamer is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.