appinitdev commited on
Commit
89f817e
verified
1 Parent(s): 4a7a8c4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -45
app.py CHANGED
@@ -1,50 +1,17 @@
1
  import os
2
- import torch
3
- from diffusers import AutoPipelineForText2Image
4
- import gradio as gr
5
 
6
- # Detectar dispositivo
7
- device = "cuda" if torch.cuda.is_available() else "cpu"
8
-
9
- # Cargar modelo con token (OBLIGATORIO para FLUX)
10
- pipe = AutoPipelineForText2Image.from_pretrained(
11
- "black-forest-labs/FLUX.1-dev",
12
- torch_dtype=torch.float16, # m谩s compatible que bfloat16
13
- token=os.getenv("HF_TOKEN") # <-- clave aqu铆
14
  )
15
- pipe = pipe.to(device)
16
-
17
- # Optimizaci贸n (MUY recomendado en Spaces)
18
- pipe.enable_attention_slicing()
19
- pipe.enable_vae_slicing()
20
-
21
- # Opcional: si tienes poca VRAM
22
- # pipe.enable_model_cpu_offload()
23
 
24
- # Cargar LoRA
25
- try:
26
- pipe.load_lora_weights(
27
- "enhanceaiteam/Flux-uncensored-v2",
28
- weight_name="lora.safetensors"
29
- )
30
- except Exception as e:
31
- print("Error cargando LoRA:", e)
32
-
33
- # Funci贸n para generar imagen
34
- def generate(prompt):
35
- image = pipe(
36
- prompt,
37
- num_inference_steps=20, # m谩s r谩pido
38
- guidance_scale=7.5
39
- ).images[0]
40
- return image
41
-
42
- # UI
43
- demo = gr.Interface(
44
- fn=generate,
45
- inputs=gr.Textbox(label="Prompt"),
46
- outputs=gr.Image(label="Resultado"),
47
- title="FLUX + LoRA Demo"
48
- )
49
 
50
- demo.launch()
 
 
 
 
 
 
1
  import os
2
+ from huggingface_hub import InferenceClient
 
 
3
 
4
+ client = InferenceClient(
5
+ provider="fal-ai",
6
+ api_key=os.environ["HF_TOKEN"],
 
 
 
 
 
7
  )
 
 
 
 
 
 
 
 
8
 
9
+ with open("cat.png", "rb") as image_file:
10
+ input_image = image_file.read()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
+ # output is a PIL.Image object
13
+ image = client.image_to_image(
14
+ input_image,
15
+ prompt="Turn the cat into a tiger.",
16
+ model="ScottzillaSystems/qwen-image-edit-plus-nsfw-lora",
17
+ )