arevedudaa commited on
Commit
c5a984f
·
verified ·
1 Parent(s): fb45a9b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -26
app.py CHANGED
@@ -1,29 +1,25 @@
1
- from fastapi import FastAPI
2
- from gradio_client import Client, handle_file
 
3
 
4
  app = FastAPI()
5
 
6
- @app.post("/generate_image")
7
- async def generate_image():
8
- client = Client("yanze/PuLID-FLUX")
9
- result = client.predict(
10
- prompt="portrait, color, cinematic",
11
- id_image=handle_file('https://d3lzcn6mbbadaf.cloudfront.net/media/details/ANI-20241109170223.jpg'),
12
- start_step=0,
13
- guidance=4,
14
- seed="-1",
15
- true_cfg=1,
16
- width=896,
17
- height=1152,
18
- num_steps=20,
19
- id_weight=1,
20
- neg_prompt="bad quality, worst quality, text, signature, watermark, extra limbs",
21
- timestep_to_start_cfg=1,
22
- max_sequence_length=128,
23
- api_name="/generate_image"
24
- )
25
- # The result is a tuple containing:
26
- # [0] filepath (str): the generated image path,
27
- # [1] used seed (str): the seed value used,
28
- # [2] output gallery (list of dicts): additional output information.
29
- return {"result": result}
 
1
+ from fastapi import FastAPI, Query
2
+ import subprocess
3
+ import json
4
 
5
  app = FastAPI()
6
 
7
+ @app.get("/generate")
8
+ async def generate(
9
+ prompt: str,
10
+ image_url: str,
11
+ format: str = "landscape",
12
+ numberofimages: int = 1
13
+ ):
14
+ # Ensure number of images doesn't exceed the limit
15
+ if numberofimages > 5:
16
+ numberofimages = 5
17
+
18
+ # Run the Python script
19
+ command = f'python flux1.py --prompt "{prompt}" --image_url "{image_url}" --format {format} --numberofimages {numberofimages}'
20
+ result = subprocess.run(command, shell=True, capture_output=True, text=True)
21
+
22
+ # Extract URLs from the output
23
+ urls = [line.split(": ")[1].strip() for line in result.stdout.split("\n") if "Generated Image" in line]
24
+
25
+ return {"urls": urls}