-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
69 lines (58 loc) · 1.81 KB
/
run.py
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 os
from typing import List, Optional
import numpy as np
import gradio as gr
from app import App
from configs import Config
from utils import EnvVars
from app.app import ImageGenerationParams
def create_app(region: str, profile: Optional[str], project: str) -> App:
return App(
region_name=region,
profile_name=profile,
project_name=project
)
def generate_images(image: np.ndarray, prompt: str, app: App) -> List[np.ndarray]:
params = ImageGenerationParams(prompt=prompt, image=image)
return app.invoke(params)
def main():
config = Config.load()
profile_name = os.environ.get(EnvVars.AWS_PROFILE_NAME.value)
app = create_app(
region=config.resources.region_name,
profile=profile_name,
project=config.resources.project_name
)
interface = gr.Interface(
fn=lambda img, prompt: generate_images(img, prompt, app),
inputs=[
gr.Image(label="Upload Image", type="numpy"),
gr.Textbox(
label="Enter Prompt",
placeholder="e.g. a photo of a man portrayed as Iron Man"
),
],
outputs=gr.Gallery(
label="Generated Images",
show_label=True,
elem_id="gallery"
),
title="🧞♂️Persona Genie",
description=(
"Create your own AI avatar photo in 10 seconds! "
"Begin your prompt with 'a photo of a man (or woman)...'. "
"For example, 'a photo of a man portrayed as Iron Man'."
),
allow_flagging="never",
examples=[],
cache_examples=False
)
interface.launch(
share=False,
debug=False,
show_error=True,
server_name="0.0.0.0",
server_port=7860
)
if __name__ == "__main__":
main()