Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from gradio_client import Client
|
3 |
+
|
4 |
+
def get_instantID(portrait_in, prompt):
|
5 |
+
client = Client("https://instantx-instantid.hf.space/")
|
6 |
+
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"
|
7 |
+
result = client.predict(
|
8 |
+
portrait_in, # filepath in 'Upload a photo of your face' Image component
|
9 |
+
None, # filepath in 'Upload a reference pose image (optional)' Image component
|
10 |
+
prompt, # str in 'Prompt' Textbox component
|
11 |
+
negative_prompt, # str in 'Negative Prompt' Textbox component
|
12 |
+
"(No style)", # Literal['(No style)', 'Watercolor', 'Film Noir', 'Neon', 'Jungle', 'Mars', 'Vibrant Color', 'Snow', 'Line art'] in 'Style template' Dropdown component
|
13 |
+
True, # bool in 'Enhance non-face region' Checkbox component
|
14 |
+
20, # float (numeric value between 20 and 100) in 'Number of sample steps' Slider component
|
15 |
+
0.8, # float (numeric value between 0 and 1.5) in 'IdentityNet strength (for fedility)' Slider component
|
16 |
+
0.8, # float (numeric value between 0 and 1.5) in 'Image adapter strength (for detail)' Slider component
|
17 |
+
5, # float (numeric value between 0.1 and 10.0) in 'Guidance scale' Slider component
|
18 |
+
0, # float (numeric value between 0 and 2147483647) in 'Seed' Slider component
|
19 |
+
api_name="/generate_image"
|
20 |
+
)
|
21 |
+
print(result)
|
22 |
+
return result[0]
|
23 |
+
|
24 |
+
def get_video(image_in, prompt):
|
25 |
+
client = Client("https://modelscope-i2vgen-xl.hf.space/")
|
26 |
+
result = client.predict(
|
27 |
+
image_in,
|
28 |
+
prompt
|
29 |
+
)
|
30 |
+
print(result)
|
31 |
+
return result
|
32 |
+
|
33 |
+
def infer(image_in, prompt):
|
34 |
+
iid_img = get_instantID(image_in, prompt)
|
35 |
+
video_res = get_video(iid_img, prompt)
|
36 |
+
print(video_res)
|
37 |
+
return video_res
|
38 |
+
|
39 |
+
gr.Interface(
|
40 |
+
fn = infer,
|
41 |
+
inputs = [
|
42 |
+
gr.Image(type="filepath"),
|
43 |
+
gr.Textbox()
|
44 |
+
],
|
45 |
+
outputs = [
|
46 |
+
gr.Video()
|
47 |
+
]
|
48 |
+
).launch()
|