mertol1 commited on
Commit
16cf6ae
1 Parent(s): 8c00444

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -13
app.py CHANGED
@@ -1,21 +1,43 @@
1
  import gradio as gr
2
  import requests
 
 
 
 
 
 
3
 
4
  def generate_image(prompt):
5
- r = requests.post(
6
- "https://api.deepai.org/api/text2img",
7
- data={
8
- 'text': prompt,
9
- },
10
- headers={'api-key': '5afe345e-57fd-4fd7-8a77-d06ce59f07ad'}
11
- )
12
- return r.json()['output_url']
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
 
14
  iface = gr.Interface(
15
- generate_image,
16
- "text",
17
- "image",
18
- title="AI Resim Oluşturucu",
19
- description="Metin girin ve AI'nın bir resim oluşturmasını izleyin!")
 
20
 
21
  iface.launch(share=True)
 
1
  import gradio as gr
2
  import requests
3
+ from PIL import Image
4
+ from io import BytesIO
5
+
6
+ # Replace 'YOUR_API_KEY' with your actual DeepAI API key
7
+ API_KEY = "5afe345e-57fd-4fd7-8a77-d06ce59f07ad"
8
+ DEEP_AI_URL = "https://api.deepai.org/api/text2img"
9
 
10
  def generate_image(prompt):
11
+ # Set up the API request parameters
12
+ data = {
13
+ 'text': prompt,
14
+ 'api_key': API_KEY,
15
+ }
16
+
17
+ # Make the request to the DeepAI API
18
+ response = requests.post(DEEP_AI_URL, data=data)
19
+
20
+ # Check if the request was successful
21
+ if response.status_code == 200:
22
+ # Parse the response to get the image URL or binary data
23
+ response_data = response.json()
24
+ image_url = response_data['output_url']
25
+
26
+ # For the sake of this example, we assume the image URL is directly downloadable
27
+ image_response = requests.get(image_url)
28
+ image = Image.open(BytesIO(image_response.content))
29
+
30
+ # Convert the image to a format that Gradio can display
31
+ return image
32
+ else:
33
+ return "Error generating image"
34
 
35
  iface = gr.Interface(
36
+ fn=generate_image,
37
+ inputs=gr.inputs.Text(label="Enter a prompt"),
38
+ outputs=gr.outputs.Image(type="auto", label="Generated Image"),
39
+ title="AI Image Generator",
40
+ description="Enter a text prompt to generate an image."
41
+ )
42
 
43
  iface.launch(share=True)