ysharma HF staff commited on
Commit
ce4a26c
·
1 Parent(s): aa2a7d8

created app.py

Browse files
Files changed (1) hide show
  1. app.py +57 -0
app.py ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ # GPT-J-6B API
4
+ API_URL = "https://api-inference.huggingface.co/models/EleutherAI/gpt-j-6B"
5
+ prompt = """
6
+ word: risk
7
+ poem using word: And then the day came,
8
+ when the risk
9
+ to remain tight
10
+ in a bud
11
+ was more painful
12
+ than the risk
13
+ it took
14
+ to blossom.
15
+
16
+ word: """
17
+
18
+ text = "A few clouded the sun, not enough to cloud the sky, not enough to bring a cloud, not enough to bring a storm"
19
+ steps, width, height, images, diversity = '50','256','256','1',15
20
+ gr.Interface.load("spaces/multimodalart/latentdiffusion")(text, steps, width, height, images, diversity)[0]
21
+
22
+ def poem_generate(word):
23
+ prompt = prompt + word + "\n" + "poem using word: "
24
+ json_ = {"inputs": prompt,
25
+ "parameters":
26
+ {
27
+ "top_p": 0.9,
28
+ "temperature": 1.1,
29
+ "max_new_tokens": 50,
30
+ "return_full_text": False
31
+ }}
32
+ response = requests.post(API_URL, json=json_)
33
+ output = response.json()
34
+ poem = output[0]['generated_text'].spilt("\n\n")[0] +"."
35
+ return poem
36
+
37
+ def poem_to_image(poem):
38
+ poem = " ".join(poem[1:].split('\n'))
39
+ poem = poem + " oil on canvas."
40
+ steps, width, height, images, diversity = '50','256','256','1',15
41
+ img = gr.Interface.load("spaces/multimodalart/latentdiffusion")(poem, steps, width, height, images, diversity)[0]
42
+ return img
43
+
44
+ demo = gr.Blocks()
45
+
46
+ with demo:
47
+ input_word = gr.Textbox(placeholder="Enter a word here to create a Poem on..")
48
+ poem_txt = gr.Textbox(lines=7)
49
+ output_image = gr.Image(type="filepath")
50
+
51
+ b1 = gr.Button("Generate Poem")
52
+ b2 = gr.Button("Generate Image")
53
+
54
+ b1.click(poem_generate, input_word, poem_txt)
55
+ b2.click(poem_to_image, poem_txt, output_image)
56
+
57
+ demo.launch(enable_queue=True, debug=True)