Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -4,20 +4,24 @@ import requests
|
|
4 |
from PIL import Image
|
5 |
import io
|
6 |
|
7 |
-
def generate_text(prompt,maxi,cohere_api_key):
|
8 |
co = cohere.Client(cohere_api_key)
|
9 |
|
10 |
-
response = co.generate(
|
11 |
-
|
12 |
-
|
13 |
-
|
|
|
|
|
|
|
|
|
14 |
|
15 |
-
def generate_image(prompt,gradio_api_key):
|
16 |
r = requests.post('https://clipdrop-api.co/text-to-image/v1',
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
)
|
22 |
|
23 |
if r.ok:
|
@@ -25,22 +29,29 @@ def generate_image(prompt,gradio_api_key):
|
|
25 |
return images
|
26 |
else:
|
27 |
raise ValueError("Failed to generate image")
|
28 |
-
|
29 |
-
def text_and_image_generator(prompt,maxi,cohere_api_key,gradio_api_key):
|
30 |
-
cohere_api_key = "3kUv9DkIN6vtDUhUXFnYyk3cqy53VWuDfC6g3mp4"
|
31 |
-
gradio_api_key = "e35a803cffac3d96f1c364a1bb8ddf00fd702be129881b1acb36f963c0ba86489cad39a6cb6f15f7cbfe919a3c4eb46e"
|
32 |
-
text = generate_text(f"Generate a story with {prompt}. Conclude the generated story properly.",maxi,cohere_api_key)
|
33 |
-
image = generate_image(text,gradio_api_key)
|
34 |
-
title = generate_text(f"title for the story {prompt} within 5 words",5,cohere_api_key)
|
35 |
|
36 |
-
|
|
|
|
|
|
|
|
|
|
|
37 |
|
38 |
app = gr.Interface(
|
39 |
-
title="Story and Image Generator",
|
40 |
fn=text_and_image_generator,
|
41 |
-
inputs
|
42 |
-
|
43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
)
|
45 |
|
46 |
-
app.launch()
|
|
|
4 |
from PIL import Image
|
5 |
import io
|
6 |
|
7 |
+
def generate_text(prompt, maxi, cohere_api_key):
|
8 |
co = cohere.Client(cohere_api_key)
|
9 |
|
10 |
+
response = co.generate(
|
11 |
+
model='xlarge', # Specify the model you are using
|
12 |
+
prompt=prompt,
|
13 |
+
temperature=0.7,
|
14 |
+
max_tokens=maxi,
|
15 |
+
stop_sequences=["--END--"]
|
16 |
+
)
|
17 |
+
return response.generations[0].text
|
18 |
|
19 |
+
def generate_image(prompt, gradio_api_key):
|
20 |
r = requests.post('https://clipdrop-api.co/text-to-image/v1',
|
21 |
+
files={
|
22 |
+
'prompt': (None, prompt, 'text/plain')
|
23 |
+
},
|
24 |
+
headers={'x-api-key': gradio_api_key}
|
25 |
)
|
26 |
|
27 |
if r.ok:
|
|
|
29 |
return images
|
30 |
else:
|
31 |
raise ValueError("Failed to generate image")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
+
def text_and_image_generator(prompt, maxi, cohere_api_key, gradio_api_key):
|
34 |
+
text = generate_text(f"Generate a story with {prompt}. Conclude the generated story properly.", maxi, cohere_api_key)
|
35 |
+
image = generate_image(text, gradio_api_key)
|
36 |
+
title = generate_text(f"title for the story {prompt} within 5 words", 5, cohere_api_key)
|
37 |
+
|
38 |
+
return title, text, image
|
39 |
|
40 |
app = gr.Interface(
|
|
|
41 |
fn=text_and_image_generator,
|
42 |
+
inputs=[
|
43 |
+
gr.Textbox(label="Enter your prompt to generate a story", lines=2, placeholder="Type your prompt here..."),
|
44 |
+
gr.Slider(320, 1000, step=1, label="Story length"),
|
45 |
+
gr.Textbox(label="Cohere API Key", type="password"),
|
46 |
+
gr.Textbox(label="Gradio API Key", type="password")
|
47 |
+
],
|
48 |
+
outputs=[
|
49 |
+
gr.Textbox(label="Story title"),
|
50 |
+
gr.Textbox(label="Story"),
|
51 |
+
gr.Image(type="pil", label="Image based on the Generated story")
|
52 |
+
],
|
53 |
+
title="Story and Image Generator",
|
54 |
+
theme="dark"
|
55 |
)
|
56 |
|
57 |
+
app.launch()
|