Spaces:
Sleeping
Sleeping
Delete app.py
Browse files
app.py
DELETED
|
@@ -1,45 +0,0 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
from azure.ai.vision.imageanalysis import ImageAnalysisClient
|
| 3 |
-
from azure.ai.vision.imageanalysis.models import VisualFeatures
|
| 4 |
-
from azure.core.credentials import AzureKeyCredential
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
def ocr_image_file(image1, end_point, API_Key):
|
| 8 |
-
|
| 9 |
-
if (end_point == '' or API_Key == ''):
|
| 10 |
-
output = "*** Please provide EndPoint URL and API_KEY ***"
|
| 11 |
-
else:
|
| 12 |
-
try:
|
| 13 |
-
endpoint = end_point
|
| 14 |
-
key = API_Key
|
| 15 |
-
# Create an Image Analysis client
|
| 16 |
-
client = ImageAnalysisClient(
|
| 17 |
-
endpoint=endpoint,
|
| 18 |
-
credential=AzureKeyCredential(key)
|
| 19 |
-
)
|
| 20 |
-
# [START read]
|
| 21 |
-
# Load image to analyze into a 'bytes' object
|
| 22 |
-
with open(image1, "rb") as f:
|
| 23 |
-
image_data = f.read()
|
| 24 |
-
|
| 25 |
-
# Extract text (OCR) from an image stream. This will be a synchronously (blocking) call.
|
| 26 |
-
result = client.analyze(
|
| 27 |
-
image_data=image_data,
|
| 28 |
-
visual_features=[VisualFeatures.READ]
|
| 29 |
-
)
|
| 30 |
-
if result.read is not None:
|
| 31 |
-
sentence = ''
|
| 32 |
-
for line in result.read.blocks[0].lines:
|
| 33 |
-
sentence += f" {line.text}" + "\n"
|
| 34 |
-
output = sentence
|
| 35 |
-
|
| 36 |
-
except :
|
| 37 |
-
output = "*** Please check EndPoint URL and API_KEY ***"
|
| 38 |
-
|
| 39 |
-
return output
|
| 40 |
-
|
| 41 |
-
demo = gr.Interface( ocr_image_file,
|
| 42 |
-
[gr.UploadButton("Click to Upload an Image File", file_types=["image"]), gr.Textbox(label="Enter your Endpoint URL", placeholder="URL", lines=1),gr.Textbox(type = "password", label="Enter your API-Key", placeholder="API-Key", lines=1)],
|
| 43 |
-
[gr.Textbox(label = "Output")]
|
| 44 |
-
|
| 45 |
-
).launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|