Sada8888 commited on
Commit
4c544c3
·
verified ·
1 Parent(s): 1ddf1f6

Create yml/generate-flux.py

Browse files
Files changed (1) hide show
  1. yml/generate-flux.py +30 -0
yml/generate-flux.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os, sys, random, requests
2
+ from gradio_client import Client
3
+
4
+ prompt = os.environ.get('PROMPT', '')
5
+ width = int(os.environ.get('WIDTH', 1024))
6
+ height = int(os.environ.get('HEIGHT', 1024))
7
+ run_id = os.environ.get('RUN_ID')
8
+ space_url = os.environ.get('SPACE_URL')
9
+ github_run_id = os.environ.get('GITHUB_RUN_ID')
10
+
11
+ print('1. Connecting to Flux...')
12
+ try:
13
+ client = Client('black-forest-labs/FLUX.1-dev')
14
+ seed = random.randint(1, 2147483647)
15
+
16
+ result = client.predict(prompt, seed, True, width, height, 3.5, 28, api_name='/infer')
17
+ image_path = result[0] if isinstance(result, (tuple, list)) else result
18
+
19
+ print(f'2. Uploading back to Docker Space...')
20
+ with open(image_path, 'rb') as f:
21
+ res = requests.post(f'{space_url}/api/webhook/upload', data={'run_id': run_id, 'github_run_id': github_run_id}, files={'file': f})
22
+
23
+ if res.status_code == 200:
24
+ print('3. SUCCESS!')
25
+ else:
26
+ sys.exit(1)
27
+
28
+ except Exception as e:
29
+ print(f'ERROR: {e}')
30
+ sys.exit(1)