Sada8888 commited on
Commit
3bcc335
·
verified ·
1 Parent(s): 0d98c19

Create yml/generate-cartoon.py

Browse files
Files changed (1) hide show
  1. yml/generate-cartoon.py +50 -0
yml/generate-cartoon.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 LoRA DLC Space...')
12
+ try:
13
+ client = Client('opera8/FLUX-LoRA-DLC')
14
+
15
+ # مرحله حیاتی: لود کردن مدل کارتونی Long Toons
16
+ print('2. Loading Cartoon Model (Long Toons)...')
17
+ client.predict('prithivMLmods/Flux-Long-Toon-LoRA', api_name='/add_custom_lora')
18
+
19
+ print('3. Generating Cartoon Image...')
20
+ # اجرای مدل با پارامترهای دقیق (Trigger word بصورت خودکار اضافه میشود)
21
+ result = client.predict(
22
+ prompt=f'Long toons {prompt}',
23
+ image_input=None,
24
+ cfg_scale=3.5,
25
+ steps=28,
26
+ randomize_seed=True,
27
+ seed=random.randint(1, 2147483647),
28
+ width=width,
29
+ height=height,
30
+ lora_scale=0.8,
31
+ api_name='/run_lora'
32
+ )
33
+
34
+ image_path = result[0] if isinstance(result, (tuple, list)) else result
35
+
36
+ print('4. Uploading back to Docker Space...')
37
+ with open(image_path, 'rb') as f:
38
+ res = requests.post(f'{space_url}/api/webhook/upload',
39
+ data={'run_id': run_id, 'github_run_id': github_run_id},
40
+ files={'file': f})
41
+
42
+ if res.status_code == 200:
43
+ print('5. SUCCESS!')
44
+ else:
45
+ print(f'Upload Error: {res.text}')
46
+ sys.exit(1)
47
+
48
+ except Exception as e:
49
+ print(f'CRITICAL ERROR: {e}')
50
+ sys.exit(1)