Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import base64
|
2 |
+
import io
|
3 |
+
import cv2
|
4 |
+
import requests
|
5 |
+
import json
|
6 |
+
import gradio as gr
|
7 |
+
|
8 |
+
# Define a function to call the API and get the results
|
9 |
+
def get_results(imag):
|
10 |
+
threshold=0.5
|
11 |
+
# Convert the image to base64 string
|
12 |
+
with io.BytesIO() as output:
|
13 |
+
image.save(output, format="JPEG")
|
14 |
+
base64str = base64.b64encode(output.getvalue()).decode("utf-8")
|
15 |
+
|
16 |
+
# Prepare the payload
|
17 |
+
payload = json.dumps({"base64str": base64str, "threshold": threshold})
|
18 |
+
|
19 |
+
# Send the request to the API
|
20 |
+
response = requests.put("", data=payload)
|
21 |
+
|
22 |
+
# Parse the JSON response
|
23 |
+
data = response.json()
|
24 |
+
|
25 |
+
# Access the values
|
26 |
+
firstName = data['firstName']
|
27 |
+
secondName = data['secondName']
|
28 |
+
address1 = data['address1']
|
29 |
+
address2 = data['address2']
|
30 |
+
nationalIdNumber = data['nationalIdNumber']
|
31 |
+
timeOfResponse = data['timeOfResponse']
|
32 |
+
requestInfo = data['requestInfo']
|
33 |
+
|
34 |
+
# Return the values as a list
|
35 |
+
return [firstName, secondName, address1, address2, nationalIdNumber, timeOfResponse, requestInfo]
|
36 |
+
|
37 |
+
# Define the input and output components for Gradio
|
38 |
+
image_input = gr.inputs.Image()
|
39 |
+
output_labels = ["First Name", "Second Name", "Address 1", "Address 2", "National ID Number", "Time of Response", "Request Info"]
|
40 |
+
output_component = gr.outputs.Label(num_top_classes=len(output_labels), labels=output_labels)
|
41 |
+
|
42 |
+
# Launch the Gradio interface
|
43 |
+
gr.Interface(fn=get_results, inputs=image_input, outputs=output_component).launch()
|