sun2dar commited on
Commit
532c299
·
verified ·
1 Parent(s): f197009

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -23
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(prompt=prompt,
11
- temperature=0,
12
- max_tokens=maxi)
13
- return response[0]
 
 
 
 
14
 
15
- def generate_image(prompt,gradio_api_key):
16
  r = requests.post('https://clipdrop-api.co/text-to-image/v1',
17
- files={
18
- 'prompt': (None, prompt, 'text/plain')
19
- },
20
- headers={'x-api-key': gradio_api_key}
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
- return title,text,image
 
 
 
 
 
37
 
38
  app = gr.Interface(
39
- title="Story and Image Generator",
40
  fn=text_and_image_generator,
41
- inputs = [gr.inputs.Textbox(label="Enter your prompt to generate a story"),
42
- gr.inputs.Slider(320,1000,label="Story length")],
43
- outputs= [gr.outputs.Textbox(label="Story title"),gr.outputs.Textbox(label="Story"),gr.outputs.Image(type="pil",label="Image based on the Generated story")],theme="dark"
 
 
 
 
 
 
 
 
 
 
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()