Spaces:
Runtime error
Runtime error
ritwikbiswas
commited on
Commit
•
84b6163
1
Parent(s):
fc2fabe
stable diff no testing
Browse files- app.py +75 -0
- requirements.txt +7 -0
app.py
ADDED
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import os
|
3 |
+
import openai
|
4 |
+
from diffusers import StableDiffusionPipeline, DPMSolverMultistepScheduler
|
5 |
+
import torch
|
6 |
+
|
7 |
+
model_id = "stabilityai/stable-diffusion-2-1"
|
8 |
+
pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
|
9 |
+
pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
|
10 |
+
pipe = pipe.to("cuda")
|
11 |
+
|
12 |
+
openai.api_key = os.getenv("OPENAI_API_KEY")
|
13 |
+
|
14 |
+
def generate_prompt(radio,word1,word2):
|
15 |
+
#prompt = 'Create an analogy for this phrase:\n\n{word1}'
|
16 |
+
# 50/50 in that/because
|
17 |
+
# pluralize singluar words
|
18 |
+
|
19 |
+
if radio == "normal":
|
20 |
+
prompt_in = f'Create an analogy for this phrase:\n\n{word1} is like {word2} in that:'
|
21 |
+
else:
|
22 |
+
prompt_in = f'Create a {radio} analogy for this phrase:\n\n{word1} is like {word2} in that:'
|
23 |
+
|
24 |
+
response = openai.Completion.create(
|
25 |
+
model="text-davinci-003",
|
26 |
+
prompt=prompt_in,
|
27 |
+
temperature=0.5,
|
28 |
+
max_tokens=60,
|
29 |
+
top_p=1.0,
|
30 |
+
frequency_penalty=0.0,
|
31 |
+
presence_penalty=0.0
|
32 |
+
)['choices'][0]['text']
|
33 |
+
|
34 |
+
response_txt = response.replace('\n','')
|
35 |
+
diffusion_in = f'a dramatic painting of: {response_txt.split(".")[0]}'
|
36 |
+
image = pipe(diffusion_in).images[0]
|
37 |
+
return response_txt, image
|
38 |
+
|
39 |
+
examples = [
|
40 |
+
["The Moon's orbit around Earth has"],
|
41 |
+
["The smooth Borealis basin in the Northern Hemisphere covers 40%"],
|
42 |
+
]
|
43 |
+
|
44 |
+
demo = gr.Interface(
|
45 |
+
generate_prompt,
|
46 |
+
[
|
47 |
+
gr.Radio(["normal", "dramatic", "joke"],value='normal',label="Flavor"),
|
48 |
+
gr.Textbox(label="Word 1"),
|
49 |
+
gr.Textbox(label="Word 2")
|
50 |
+
# gr.Dropdown(team_list, value=[team_list[random.randint(1,30)]], multiselect=True),
|
51 |
+
# gr.Checkbox(label="Is it the morning?"),
|
52 |
+
],
|
53 |
+
"text",
|
54 |
+
"image",
|
55 |
+
allow_flagging="never",
|
56 |
+
title="GPT-3 Analogy Lab 🧪",
|
57 |
+
description="foo tested",
|
58 |
+
css="footer {visibility: hidden}"
|
59 |
+
)
|
60 |
+
|
61 |
+
|
62 |
+
|
63 |
+
demo.launch()
|
64 |
+
#openai.api_key = os.getenv("OPENAI_API_KEY")
|
65 |
+
# openai.api_key = "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"
|
66 |
+
|
67 |
+
# response = openai.Completion.create(
|
68 |
+
# model="text-davinci-003",
|
69 |
+
# prompt="Create an analogy for this phrase:\n\nQuestions are arrows in that:",
|
70 |
+
# temperature=0.5,
|
71 |
+
# max_tokens=60,
|
72 |
+
# top_p=1.0,
|
73 |
+
# frequency_penalty=0.0,
|
74 |
+
# presence_penalty=0.0
|
75 |
+
# )
|
requirements.txt
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
openai
|
2 |
+
diffusers
|
3 |
+
transformers
|
4 |
+
accelerate
|
5 |
+
scipy
|
6 |
+
safetensors
|
7 |
+
|