Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
|
3 |
+
import dotenv
|
4 |
+
import gradio as gr
|
5 |
+
import openai
|
6 |
+
|
7 |
+
dotenv.load_dotenv()
|
8 |
+
|
9 |
+
openai.organization = os.getenv("API_ORG")
|
10 |
+
openai.api_key = os.getenv("API_KEY")
|
11 |
+
app_password = os.getenv("APP_PASSWORD")
|
12 |
+
app_username = os.getenv("APP_USERNAME")
|
13 |
+
|
14 |
+
def generate(prompt):
|
15 |
+
response = openai.Image.create(
|
16 |
+
prompt=prompt,
|
17 |
+
n=1,
|
18 |
+
size="256x256"
|
19 |
+
)
|
20 |
+
return response['data'][0]['url']
|
21 |
+
|
22 |
+
examples = [
|
23 |
+
["きのこの山"],
|
24 |
+
["たけのこの里"],
|
25 |
+
]
|
26 |
+
|
27 |
+
demo = gr.Interface(
|
28 |
+
fn=generate,
|
29 |
+
inputs=gr.components.Textbox(lines=5, label="Prompt"),
|
30 |
+
outputs=gr.components.Image(type="filepath", label="Generated Image"),
|
31 |
+
flagging_options=[],
|
32 |
+
examples=examples
|
33 |
+
)
|
34 |
+
|
35 |
+
demo.launch(share=False, auth=(app_username, app_password))
|