Eaglebelt commited on
Commit
b1e7dae
·
verified ·
1 Parent(s): 344cce7

Delete main.py

Browse files
Files changed (1) hide show
  1. main.py +0 -49
main.py DELETED
@@ -1,49 +0,0 @@
1
- import os
2
- import io
3
- import PIL.Image # Workaround for PIL/Gradio bug :contentReference[oaicite:13]{index=13}
4
- import gradio as gr
5
- from gradio_client import Client, handle_file
6
-
7
- from numpy import array
8
- # 1. Load your HF token from env
9
- HF_TOKEN = os.getenv("HF_TOKEN") # export HF_TOKEN="hf_..."
10
- # 1) Connect to the Leffa Gradio app’s predict endpoint
11
- # Use the full "/call/predict" API path as shown on the View API page
12
- client = Client("franciszzj/Leffa", hf_token=HF_TOKEN, ) # Gradio Python client
13
-
14
- def virtual_tryon(person_path, garment_path):
15
- # 2) Wrap file inputs so Gradio client uploads them correctly
16
- person_file = handle_file(person_path) # handle_file uploads the image :contentReference[oaicite:6]{index=6}
17
- garment_file = handle_file(garment_path)
18
-
19
- # 3) Build inputs in the exact order shown on the “Use via API” page :contentReference[oaicite:7]{index=7}
20
-
21
- # 4) Call the named endpoint with handle_file inputs
22
- result = client.predict(
23
- person_file, # Person Image
24
- garment_file, # Garment Image
25
- ref_acceleration=False,
26
- step=30,
27
- scale=2.5,
28
- seed=42,
29
- vt_model_type="viton_hd",
30
- vt_garment_type="upper_body",
31
- vt_repaint=False,
32
- api_name="/leffa_predict_vt"
33
- )
34
- # result[0] is the generated image filepath on the server
35
- return result[0] # Gradio will download & display this file
36
-
37
- # 5) Gradio UI
38
- with gr.Blocks() as demo:
39
- gr.Markdown("## Leffa Virtual Try-On")
40
- with gr.Row():
41
- src = gr.Image(sources="upload", type="filepath", label="Person Image")
42
- ref = gr.Image(sources="upload", type="filepath", label="Garment Image")
43
- out = gr.Image(type="filepath", label="Result", )
44
- btn = gr.Button("Generate")
45
- btn.click(virtual_tryon, [src, ref], out)
46
-
47
- demo.launch(share=True,
48
- show_error=True,
49
- pwa=True,)