JibexBanks commited on
Commit
e2719e7
·
1 Parent(s): 1bb766f

changed the content of the app.py

Browse files
Files changed (1) hide show
  1. app.py +58 -0
app.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import requests
3
+
4
+ def dowload_image(img_url):
5
+ import random
6
+
7
+
8
+
9
+ image_url = img_url
10
+ # Define the local filename to save the image as
11
+ i = random.choice(range(1,100))
12
+ filename = f'downloaded_image{i}.png'
13
+
14
+ response = requests.get(image_url)
15
+
16
+ # Check if the request was successful (status code 200)
17
+ if response.status_code == 200:
18
+ # Open the file in write-binary mode ('wb')
19
+ with open(filename, 'wb') as file:
20
+ file.write(response.content)
21
+ print(f"Image downloaded successfully as {filename}!")
22
+ return filename
23
+ else:
24
+ print(f"Failed to download image. Status code: {response.status_code}")
25
+
26
+
27
+
28
+ def text2Image(prompt):
29
+
30
+ url = "https://ai-text-to-image-generator-flux-free-api.p.rapidapi.com/aaaaaaaaaaaaaaaaaiimagegenerator/quick.php"
31
+
32
+ payload = {
33
+ "prompt": prompt,
34
+ "style_id": 4,
35
+ "size": "1-1"
36
+ }
37
+ headers = {
38
+ "x-rapidapi-key": "21a0339821mshb29d50e4919dc6dp1f25f6jsnbb6b8ece8c63",
39
+ "x-rapidapi-host": "ai-text-to-image-generator-flux-free-api.p.rapidapi.com",
40
+ "Content-Type": "application/json"
41
+ }
42
+
43
+ response = requests.post(url, json=payload, headers=headers)
44
+
45
+ print(response.json())
46
+ response = response.json()
47
+ img_url = response["result"]["data"]["results"][1]["origin"]
48
+
49
+ return dowload_image(img_url=img_url)
50
+
51
+
52
+
53
+ gr.Interface(
54
+ fn=text2Image,
55
+ inputs=["text"],
56
+ outputs=["image"],
57
+ api_name="Testing.."
58
+ ).launch()