File size: 1,459 Bytes
c1a4f45
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
38
39
40
41
42
43
import base64
import io
import cv2
import requests
import json
import gradio as gr

# Define a function to call the API and get the results
def get_results(imag):
    threshold=0.5
    # Convert the image to base64 string
    with io.BytesIO() as output:
        image.save(output, format="JPEG")
        base64str = base64.b64encode(output.getvalue()).decode("utf-8")

    # Prepare the payload
    payload = json.dumps({"base64str": base64str, "threshold": threshold})

    # Send the request to the API
    response = requests.put("", data=payload)

    # Parse the JSON response
    data = response.json()

    # Access the values
    firstName = data['firstName']
    secondName = data['secondName']
    address1 = data['address1']
    address2 = data['address2']
    nationalIdNumber = data['nationalIdNumber']
    timeOfResponse = data['timeOfResponse']
    requestInfo = data['requestInfo']

    # Return the values as a list
    return [firstName, secondName, address1, address2, nationalIdNumber, timeOfResponse, requestInfo]

# Define the input and output components for Gradio
image_input = gr.inputs.Image()
output_labels = ["First Name", "Second Name", "Address 1", "Address 2", "National ID Number", "Time of Response", "Request Info"]
output_component = gr.outputs.Label(num_top_classes=len(output_labels), labels=output_labels)

# Launch the Gradio interface
gr.Interface(fn=get_results, inputs=image_input, outputs=output_component).launch()