Anustup commited on
Commit
e3f78f6
·
verified ·
1 Parent(s): 4663e5a

Update theme.py

Browse files
Files changed (1) hide show
  1. theme.py +68 -67
theme.py CHANGED
@@ -1,67 +1,68 @@
1
- import random
2
- import replicate
3
- import base64
4
- import os
5
-
6
- os.environ["REPLICATE_API_TOKEN"] = os.getenv("REPLICATE_API_TOKEN")
7
-
8
-
9
- def create_flux_request(prompt_for_image_generation):
10
- payload = {
11
- "prompt": prompt_for_image_generation,
12
- "guidance": 3.5,
13
- "num_outputs": 1,
14
- "aspect_ratio": "3:4"
15
- }
16
- output = replicate.run(
17
- "black-forest-labs/flux-dev",
18
- input=payload
19
- )
20
- return output
21
-
22
-
23
- def flux_generated_image(prompt_for_image_generation):
24
- try:
25
- flux_response_object = create_flux_request(prompt_for_image_generation)
26
- data_uri = flux_response_object[0].url
27
- header, encoded = data_uri.split(',', 1)
28
- file_data = base64.b64decode(encoded)
29
- random_int_for_file_prefix = random.randint(1, 1000000)
30
- output_image_file_name = f"{random_int_for_file_prefix}_ide_theme_image.png"
31
- with open(output_image_file_name, "wb") as f:
32
- f.write(file_data)
33
- return {"success": True, "file_name": output_image_file_name}
34
- except Exception as e:
35
- return {"success": False, "error": e}
36
-
37
-
38
- def create_flux_request_seed(prompt_for_image_generation, seed, aspect_ratio):
39
- print(f"YE SEED HAI MEPE:{seed}")
40
- payload = {
41
- "prompt": prompt_for_image_generation,
42
- "guidance": 3.5,
43
- "num_outputs": 1,
44
- "aspect_ratio": str(aspect_ratio),
45
- "seed": int(seed)
46
-
47
- }
48
- output = replicate.run(
49
- "black-forest-labs/flux-dev",
50
- input=payload
51
- )
52
- return output
53
-
54
-
55
- def flux_generated_image_seed(prompt_for_image_generation, seed, aspect_ratio):
56
- try:
57
- flux_response_object = create_flux_request_seed(prompt_for_image_generation, seed, aspect_ratio)
58
- data_uri = flux_response_object[0].url
59
- header, encoded = data_uri.split(',', 1)
60
- file_data = base64.b64decode(encoded)
61
- random_int_for_file_prefix = random.randint(1, 1000000)
62
- output_image_file_name = f"{random_int_for_file_prefix}_ide_theme_image.png"
63
- with open(output_image_file_name, "wb") as f:
64
- f.write(file_data)
65
- return {"success": True, "file_name": output_image_file_name}
66
- except Exception as e:
67
- return {"success": False, "error": e}
 
 
1
+ import random
2
+ import replicate
3
+ import base64
4
+ import os
5
+
6
+ os.environ["REPLICATE_API_TOKEN"] = os.getenv("REPLICATE_API_TOKEN")
7
+
8
+
9
+ def create_flux_request(prompt_for_image_generation):
10
+ payload = {
11
+ "prompt": prompt_for_image_generation,
12
+ "guidance": 3.5,
13
+ "num_outputs": 1,
14
+ "aspect_ratio": "3:4"
15
+ }
16
+ output = replicate.run(
17
+ "black-forest-labs/flux-dev",
18
+ input=payload
19
+ )
20
+ return output
21
+
22
+
23
+ def flux_generated_image(prompt_for_image_generation):
24
+ try:
25
+ p = "Create Non NSFW image." + prompt_for_image_generation
26
+ flux_response_object = create_flux_request(p)
27
+ data_uri = flux_response_object[0].url
28
+ header, encoded = data_uri.split(',', 1)
29
+ file_data = base64.b64decode(encoded)
30
+ random_int_for_file_prefix = random.randint(1, 1000000)
31
+ output_image_file_name = f"{random_int_for_file_prefix}_ide_theme_image.png"
32
+ with open(output_image_file_name, "wb") as f:
33
+ f.write(file_data)
34
+ return {"success": True, "file_name": output_image_file_name}
35
+ except Exception as e:
36
+ return {"success": False, "error": e}
37
+
38
+
39
+ def create_flux_request_seed(prompt_for_image_generation, seed, aspect_ratio):
40
+ print(f"YE SEED HAI MEPE:{seed}")
41
+ payload = {
42
+ "prompt": prompt_for_image_generation,
43
+ "guidance": 3.5,
44
+ "num_outputs": 1,
45
+ "aspect_ratio": str(aspect_ratio),
46
+ "seed": int(seed)
47
+
48
+ }
49
+ output = replicate.run(
50
+ "black-forest-labs/flux-dev",
51
+ input=payload
52
+ )
53
+ return output
54
+
55
+
56
+ def flux_generated_image_seed(prompt_for_image_generation, seed, aspect_ratio):
57
+ try:
58
+ flux_response_object = create_flux_request_seed(prompt_for_image_generation, seed, aspect_ratio)
59
+ data_uri = flux_response_object[0].url
60
+ header, encoded = data_uri.split(',', 1)
61
+ file_data = base64.b64decode(encoded)
62
+ random_int_for_file_prefix = random.randint(1, 1000000)
63
+ output_image_file_name = f"{random_int_for_file_prefix}_ide_theme_image.png"
64
+ with open(output_image_file_name, "wb") as f:
65
+ f.write(file_data)
66
+ return {"success": True, "file_name": output_image_file_name}
67
+ except Exception as e:
68
+ return {"success": False, "error": e}