arevedudaa commited on
Commit
7affc0c
·
verified ·
1 Parent(s): dd0645c

Delete flux_api.py

Browse files
Files changed (1) hide show
  1. flux_api.py +0 -59
flux_api.py DELETED
@@ -1,59 +0,0 @@
1
-
2
- import argparse
3
- import requests
4
- from gradio_client import Client, handle_file
5
-
6
- def generate_image(prompt, image_url=None, image_file=None):
7
- client = Client("yanze/PuLID-FLUX")
8
-
9
- # Determine input image
10
- if image_url:
11
- id_image = handle_file(image_url)
12
- elif image_file:
13
- id_image = handle_file(image_file)
14
- else:
15
- return "Error: Please provide an image URL or upload an image file."
16
-
17
- try:
18
- result = client.predict(
19
- prompt=prompt,
20
- id_image=id_image,
21
- start_step=0,
22
- guidance=4,
23
- seed="-1",
24
- true_cfg=1,
25
- width=896,
26
- height=1152,
27
- num_steps=20,
28
- id_weight=1,
29
- neg_prompt="bad quality, worst quality, text, signature, watermark, extra limbs",
30
- timestep_to_start_cfg=1,
31
- max_sequence_length=128,
32
- api_name="/generate_image"
33
- )
34
-
35
- base_url = "https://yanze-pulid-flux.hf.space/file="
36
- file_path = result[0]
37
- full_url = f"{base_url}{file_path}"
38
-
39
- # Download and save image
40
- response = requests.get(full_url)
41
- if response.status_code == 200:
42
- with open("output_image.jpg", "wb") as f:
43
- f.write(response.content)
44
- print("Image saved as output_image.jpg")
45
-
46
- return full_url
47
- except Exception as e:
48
- return f"Error during prediction: {str(e)}"
49
-
50
- if __name__ == "__main__":
51
- parser = argparse.ArgumentParser(description="Generate images using PuLID-FLUX")
52
- parser.add_argument("--prompt", type=str, required=True, help="Text prompt for the image generation")
53
- parser.add_argument("--image_url", type=str, default=None, help="Optional image URL")
54
- parser.add_argument("--image_file", type=str, default=None, help="Optional local image file path")
55
-
56
- args = parser.parse_args()
57
-
58
- output_url = generate_image(args.prompt, args.image_url, args.image_file)
59
- print(f"Generated Image URL: {output_url}")