File size: 2,674 Bytes
26d2e03
39efdd8
daee6bf
ee62acc
26d2e03
cb2e1df
de28a32
 
 
 
 
cb2e1df
 
 
 
4a8e122
cb2e1df
5461745
 
cb2e1df
 
 
4a8e122
 
cb2e1df
954ff05
1d09840
954ff05
cb2e1df
 
bf0b2b5
 
 
0f347be
 
80ed77f
0f347be
80ed77f
 
fb2b03d
111e0cd
21d0068
bf0b2b5
 
635f9dc
 
de28a32
 
 
 
cb2e1df
de28a32
 
 
583d821
 
cb2e1df
 
11e2a0f
 
de28a32
ed352b4
de28a32
 
679d980
 
de28a32
 
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
58
59
60
61
62
63
64
65
66
67
68
69
import gradio as gr
import requests
import os
#import json

def faceSwap(file1, file2):
    # Process the uploaded files (e.g., read content, perform calculations, etc.)
    # Replace the following lines with your actual processing logic
    #file1_content = file1.read().decode("utf-8")
    #file2_content = file2.read().decode("utf-8")
    #result = f"File 1 content:\n{file1_content}\n\nFile 2 content:\n{file2_content}"
    #result = "It worked"

    #FaceSwap Stuff
    url = "https://api.prodia.com/v1/faceswap"
    api_key=os.getenv("PRODIA_API_KEY")
    payload = {
        "sourceUrl": f"https://thefisher86-faceswappa.hf.space/file={file1}",
        "targetUrl": f"https://thefisher86-faceswappa.hf.space/file={file2}"
    }
    headers = {
        "accept": "application/json",
        "content-type": "application/json",
        "X-Prodia-Key": api_key
    }
    print(url)
    print(payload)
    print(headers)
    response = requests.post(url, json=payload, headers=headers)

    if response.status_code == 200:
        jobNumber = response.json().get("job")
        print(f"Job created with ID: {jobNumber}")
        urlBase = "https://api.prodia.com/v1/job/"
        headers = {"accept": "application/json", "content-type": "application/json", "X-Prodia-Key": api_key}
        jobResponse = requests.get(urlBase + jobNumber, headers=headers)
        print(f"JobResponse Value: {jobResponse}")
        print(f"Job Status Code: {jobResponse.status_code}")
        genStatus = jobResponse.json()
        print(f"Status: {genStatus}")
        result = f"https://images.prodia.xyz/{jobNumber}.png"
        #result = "yay"
    else:
        print(f"Couldn't create job. {response.status_code}")
        result = "fuck"
        
    return result

# Create a Gradio interface with two file upload components
iface = gr.Interface(
    fn=faceSwap,
    inputs=[
#        gr.inputs.File(label="Upload File 1"),
#        gr.inputs.File(label="Upload File 2")
        gr.Image(label="Face File", value="FaceFile", interactive=True, show_share_button=True, container=True, type='filepath', sources=('upload', 'webcam', 'clipboard')),
        gr.Image(label="Body File", value="BodyFile", interactive=True, show_share_button=True, container=True, type='filepath', sources=('upload', 'webcam', 'clipboard'))
    ],
    outputs=[
        gr.Textbox(label="Result")
        #gr.Image(type="pil", show_download_button=True)
    ],
    #gr.Textbox(label="Job Number", placeholder="will fill in when job number received", interactive=False),
    title="File Upload Interface",
    description="Upload two files and process them."
)

# Launch the Gradio interface
iface.launch()