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