File size: 2,074 Bytes
a7cbda8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from gradio_client import Client

def get_instantID(portrait_in, prompt):
    client = Client("https://instantx-instantid.hf.space/")
    negative_prompt = "(lowres, low quality, worst quality:1.2), (text:1.2), watermark, (frame:1.2), deformed, ugly, deformed eyes, blur, out of focus, blurry, deformed cat, deformed, photo, anthropomorphic cat, monochrome, photo, pet collar, gun, weapon, blue, 3d, drones, drone, buildings in background, green"
    result = client.predict(
		portrait_in,	# filepath  in 'Upload a photo of your face' Image component
		None,	# filepath  in 'Upload a reference pose image (optional)' Image component
	    prompt,	# str  in 'Prompt' Textbox component
		negative_prompt,	# str  in 'Negative Prompt' Textbox component
		"(No style)",	# Literal['(No style)', 'Watercolor', 'Film Noir', 'Neon', 'Jungle', 'Mars', 'Vibrant Color', 'Snow', 'Line art']  in 'Style template' Dropdown component
		True,	# bool  in 'Enhance non-face region' Checkbox component
		20,	# float (numeric value between 20 and 100) in 'Number of sample steps' Slider component
		0.8,	# float (numeric value between 0 and 1.5) in 'IdentityNet strength (for fedility)' Slider component
		0.8,	# float (numeric value between 0 and 1.5) in 'Image adapter strength (for detail)' Slider component
		5,	# float (numeric value between 0.1 and 10.0) in 'Guidance scale' Slider component
		0,	# float (numeric value between 0 and 2147483647) in 'Seed' Slider component
		api_name="/generate_image"
    )
    print(result)
    return result[0]

def get_video(image_in, prompt):
    client = Client("https://modelscope-i2vgen-xl.hf.space/")
    result = client.predict(
        image_in,
        prompt
    )
    print(result)
    return result

def infer(image_in, prompt):
    iid_img = get_instantID(image_in, prompt)
    video_res = get_video(iid_img, prompt)
    print(video_res)
    return video_res

gr.Interface(
    fn = infer,
    inputs = [
        gr.Image(type="filepath"),
        gr.Textbox()
    ],
    outputs = [
        gr.Video()
    ]
).launch()