File size: 1,248 Bytes
9a63fef
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from fastapi import FastAPI
import base64
from gradio_client import Client, handle_file

app=FastAPI()



def Runn():
    client = Client("bytedance-research/UNO-FLUX")
    result = client.predict(
        prompt="an orange cat in the field",
        width=512,
        height=512,
        guidance=4,
        num_steps=25,
        seed=-1,
        image_prompt1=handle_file('https://raw.githubusercontent.com/gradio-app/gradio/main/test/test_files/bus.png'),
        image_prompt2=handle_file('https://raw.githubusercontent.com/gradio-app/gradio/main/test/test_files/bus.png'),
        image_prompt3=handle_file('https://raw.githubusercontent.com/gradio-app/gradio/main/test/test_files/bus.png'),
        image_prompt4=handle_file('https://raw.githubusercontent.com/gradio-app/gradio/main/test/test_files/bus.png'),
        api_name="/gradio_generate"
    )
    
    preview_path, final_image_path = result
    
    # Read and encode as base64
    with open(final_image_path, 'rb') as f:
        image_data = base64.b64encode(f.read()).decode('utf-8')
    
    return {
        "image": f"data:image/png;base64,{image_data}",
        "preview": preview_path  # or convert this too
    }


@app.get("/ss")
def SS():
    boom=Runn()
    return boom