File size: 1,656 Bytes
901e379
 
 
 
 
 
 
 
 
 
c00995a
 
 
5143658
c00995a
 
 
 
 
 
5143658
c00995a
 
 
 
 
 
5143658
901e379
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import sys
import os
import io
import base64
import json
import gradio as gr
import requests


def face_recognition_on_file(file1, file2):
    url = "http://93.127.215.33:8080/face_recognition"
    try:
        files = {'file1': open(file1, 'rb'), 'file2': open(file2, 'rb')}

        r = requests.post(url=url, files=files)
        r.raise_for_status()  # Raise an exception for bad status codes
    except requests.RequestException as e:
        raise gr.Error(f"Error occurred: {str(e)}")
    except IOError:
        raise gr.Error("Please select valid image files!")

    try:
        response = r.json()
        print(response)
        return response
    except json.JSONDecodeError:
        raise gr.Error("Invalid response from server")


with gr.Blocks() as demo:
    gr.Markdown(
        """
    # FacePlugin Online Demo

    """
    )

    with gr.TabItem("Face Recognition"):
        with gr.Row():
            with gr.Column():
                first_input = gr.Image(type='filepath')
                gr.Examples(['images/rec_5.jpg', 'images/rec_1.jpg', 'images/9.png', 'images/rec_3.jpg'],
                            inputs=first_input)
                start_button = gr.Button("Run")
            with gr.Column():
                second_input = gr.Image(type='filepath')
                gr.Examples(['images/rec_6.jpg', 'images/rec_2.jpg', 'images/10.jpg', 'images/rec_4.jpg'],
                            inputs=second_input)

            with gr.Column():
                app_output = [gr.JSON()]

        start_button.click(face_recognition_on_file, inputs=[first_input, second_input], outputs=app_output)
demo.queue().launch(share=True)