File size: 1,643 Bytes
d5080b5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import base64
import io
import cv2
import requests
import json
import gradio as gr
import os
from PIL import Image

# Accessing a specific environment variable
api_key = os.environ.get('PXiVision')

# Checking if the environment variable exists
if not api_key:
    print("PXiVision environment variable is not set.")
    exit()

# Define a function to call the API and get the results
def get_results(image):
    threshold = 0.5
    
    # Convert the NumPy array to PIL image
    image = Image.fromarray(image)

    # 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, "UID": "huggingfacetestsayed"})

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

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


    # Access the values
    num = data['num']
    char = data['char']
    timeOfResponse = data['time']
    requestInfo = data['info']
    return [num, char, timeOfResponse, requestInfo]

# Define the input component for Gradio
image_input = gr.inputs.Image()  # Adjust the shape according to your requirements

# Define the output components for Gradio
output_components = []
for label in ["Numbers", "char", "Time of Response", "Request Info"]:
    output_components.append(gr.outputs.Textbox(label=label))

# Launch the Gradio interface
gr.Interface(fn=get_results,examples=["test.jpg"], inputs=image_input, outputs=output_components).launch(share=False)