seawolf2357 commited on
Commit
3c02b31
ยท
1 Parent(s): bd532eb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -26
app.py CHANGED
@@ -1,13 +1,12 @@
1
  import gradio as gr
2
  import requests
 
3
  from PIL import Image
4
- import io
5
-
6
- API_KEY = "ZZUIQ4OZASNRQ8B8WYHNW"
7
 
8
  def generate_image(content, style):
9
  headers = {
10
- 'Authorization': f'Bearer {API_KEY}',
11
  }
12
  json_data = {
13
  'content': content,
@@ -15,29 +14,20 @@ def generate_image(content, style):
15
  }
16
  response = requests.post('https://api.fliki.ai/v1/generate/text-to-image', headers=headers, json=json_data)
17
 
18
- if response.status_code == 200:
19
- image_url = response.json()['url']
20
- image_response = requests.get(image_url)
21
- image = Image.open(io.BytesIO(image_response.content))
22
  return image
23
  else:
24
- raise Exception(f"์˜ค๋ฅ˜ ๋ฐœ์ƒ: {response.text}")
25
-
26
- with gr.Blocks() as demo:
27
- with gr.Row():
28
- content_input = gr.Textbox(label="ํ…์ŠคํŠธ ์ž…๋ ฅ")
29
- style_input = gr.Dropdown(choices=['3d-model', 'analog-film', 'anime', 'cinematic',
30
- 'comic-book', 'digital-art', 'enhance', 'fantasy-art',
31
- 'isometric', 'line-art', 'low-poly', 'modeling-compound',
32
- 'neon-punk', 'origami', 'photographic', 'pixel-art',
33
- 'tile-texture'], label="์Šคํƒ€์ผ ์„ ํƒ")
34
- submit_button = gr.Button("์ด๋ฏธ์ง€ ์ƒ์„ฑ")
35
- output = gr.Image(label="์ƒ์„ฑ๋œ ์ด๋ฏธ์ง€", type="pil")
36
 
37
- submit_button.click(
38
- generate_image,
39
- inputs=[content_input, style_input],
40
- outputs=output
41
- )
 
 
42
 
43
- demo.launch()
 
1
  import gradio as gr
2
  import requests
3
+ import base64
4
  from PIL import Image
5
+ from io import BytesIO
 
 
6
 
7
  def generate_image(content, style):
8
  headers = {
9
+ 'Authorization': 'Bearer ZZUIQ4OZASNRQ8B8WYHNW',
10
  }
11
  json_data = {
12
  'content': content,
 
14
  }
15
  response = requests.post('https://api.fliki.ai/v1/generate/text-to-image', headers=headers, json=json_data)
16
 
17
+ # Assuming the response contains the image in base64 format
18
+ image_data = response.json().get('image', '')
19
+ if image_data:
20
+ image = Image.open(BytesIO(base64.b64decode(image_data)))
21
  return image
22
  else:
23
+ return "Error: No image returned"
 
 
 
 
 
 
 
 
 
 
 
24
 
25
+ iface = gr.Interface(
26
+ fn=generate_image,
27
+ inputs=[gr.Textbox(label="Content"), gr.Textbox(label="Style")],
28
+ outputs="image",
29
+ title="Text to Image Generator",
30
+ description="Enter a description and style to generate an image."
31
+ )
32
 
33
+ iface.launch()