File size: 2,414 Bytes
6f1ec06
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from PIL import Image
import numpy as np
import os
import json
import tempfile
import replicate # type: ignore


file_path = "comicidapi.json"
# Define the replicate API token
auth_token = os.environ.get("REPLICATE_API_TOKEN")
print (auth_token)


def load_workflow_from_file(file_path):
    with open(file_path, 'r') as file:
        return json.load(file)

def process_image(image, style, character, prompt1):
    workflow = dict()
    pil_image = Image.fromarray((image))

    prompt = f"Generate an image based on {style} style, graphic novel art, character as {character}, with high resolution, UHD, background of the image as {prompt1}"
    
    # Save the image to a temporary file
    with tempfile.NamedTemporaryFile(suffix=".jpg", delete=False) as temp_file:
        pil_image = Image.fromarray(image)
        pil_image.save(temp_file.name)
        print (temp_file.name)
        input_file = open(f"{temp_file.name}", "rb")

    workflow = load_workflow_from_file(file_path)
    workflow["6"]["inputs"]["text"] = f"{prompt}" #prompt
   
   
    # Define the API endpoind
    output = replicate.run(
        "fofr/any-comfyui-workflow:68ece9a0cd9b8de5708e012f64fa5deccd1ab7571a2e207cac0bd463b7107e79",
        input = {
        "workflow_json": json.dumps(workflow),
        "randomise_seeds": True,
        "return_temp_files": False,
        "input_file": input_file
        },
    )
    print(output)
    return(output[0])


iface = gr.Interface(
    fn=process_image,
    inputs=[
        gr.Image(label = "Upload your Image"),
        gr.Dropdown(choices=["Graphic Illustration","Anime", "ComicStrip", "Disney", "Pixar 3D", "Pixel Art", "Gothic", "Chibi"," Oil Painting"], label="Style"),
        gr.Dropdown(choices=["SuperMan","Cinderrella","SnowWhite","Elsa Frozen", "Batman", "Ariel Mermaid", "Wonder Woman", "Iron-Man","Spider-Man","Captain America","Batgirl","Blackwidow","Hulk"], label="Character"),
        gr.Textbox(lines=2, placeholder="Enter your prompt here...", label="Describe the background of the image")
    ],
    outputs=[
        gr.Image(label="Your transformed Image")
    ],
    title="Image Processing App",
    description="Select a style, character, and enter a prompt to process the image.\n In case of any error, try again with a better quality image where the face is clear and with better resolution",
    
)

# Launch the Gradio app
iface.launch()