juanelot commited on
Commit
a65b3e1
verified
1 Parent(s): 66e7106
Files changed (1) hide show
  1. app.py +13 -17
app.py CHANGED
@@ -1,24 +1,22 @@
1
  import gradio as gr
2
- from transformers import AutoModelForCausalLM, AutoTokenizer
3
- from torch import autocast
4
  import torch
5
 
6
- # Cargar el modelo y el tokenizer
7
- model_name = "ZB-Tech/Text-to-Image"
8
- tokenizer = AutoTokenizer.from_pretrained(model_name)
9
- model = AutoModelForCausalLM.from_pretrained(model_name)
 
10
 
 
11
  device = "cuda" if torch.cuda.is_available() else "cpu"
12
- model = model.to(device)
13
 
14
  # Definir la funci贸n de generaci贸n de imagen
15
  def generate_image(prompt):
16
- inputs = tokenizer(prompt, return_tensors="pt").to(device)
17
- with autocast(device):
18
- output = model.generate(**inputs)
19
- # Convertir el output en una imagen adecuada para mostrar
20
- # (El c贸digo depende de la salida del modelo)
21
- return tokenizer.decode(output[0], skip_special_tokens=True)
22
 
23
  # Crear la interfaz de Gradio
24
  iface = gr.Interface(
@@ -27,12 +25,10 @@ iface = gr.Interface(
27
  outputs=gr.outputs.Image(type="pil", label="Imagen generada"),
28
  title="Generador de Im谩genes a partir de Texto",
29
  description="Ingrese un texto y obtenga una imagen generada por IA.",
30
- theme="default", # Puedes cambiar el tema
31
- layout="vertical", # Puedes cambiar el dise帽o a 'horizontal' o 'vertical'
32
  examples=[
33
- ["a picturesque of local market. The first light of day illuminates the stone facades and worn tiles of the houses and buildings, some of which date back centuries. At the center of the scene, a cobblestone square leads to an open-air market that begins to come to life, with vendors setting up their stalls selling fruits, vegetables, flowers and local crafts. The narrow, winding streets are lined with old lanterns, now unlit, while lazy cats lounge on the stone steps. In one corner, an ancient fountain, adorned with weathered carvings, murmurs softly, adding to the tranquil atmosphere. In the background, the towers of an ancient cathedral rise, capturing the first rays of sunlight that paint the sky in soft pinks and oranges. This image should convey a sense of tranquility, beauty and a deep connection to the past, celebrating the rich history and timeless charm of the ancient village or town."]
34
  ],
35
- live=True # Si deseas que los resultados se actualicen en tiempo real
36
  )
37
 
38
  # Ejecutar la interfaz
 
1
  import gradio as gr
2
+ from diffusers import DiffusionPipeline
 
3
  import torch
4
 
5
+ # Cargar el modelo base y los pesos LoRA
6
+ model_name = "stabilityai/stable-diffusion-xl-base-1.0"
7
+ lora_weights = "ZB-Tech/Text-to-Image"
8
+ pipeline = DiffusionPipeline.from_pretrained(model_name)
9
+ pipeline.load_lora_weights(lora_weights)
10
 
11
+ # Mover el modelo a la GPU si est谩 disponible
12
  device = "cuda" if torch.cuda.is_available() else "cpu"
13
+ pipeline = pipeline.to(device)
14
 
15
  # Definir la funci贸n de generaci贸n de imagen
16
  def generate_image(prompt):
17
+ with torch.autocast(device):
18
+ image = pipeline(prompt).images[0]
19
+ return image
 
 
 
20
 
21
  # Crear la interfaz de Gradio
22
  iface = gr.Interface(
 
25
  outputs=gr.outputs.Image(type="pil", label="Imagen generada"),
26
  title="Generador de Im谩genes a partir de Texto",
27
  description="Ingrese un texto y obtenga una imagen generada por IA.",
 
 
28
  examples=[
29
+ ["A picturesque view of a local market. The first light of day illuminates the stone facades and worn tiles of the houses and buildings, some of which date back centuries. At the center of the scene, a cobblestone square leads to an open-air market that begins to come to life, with vendors setting up their stalls selling fruits, vegetables, flowers, and local crafts. The narrow, winding streets are lined with old lanterns, now unlit, while lazy cats lounge on the stone steps. In one corner, an ancient fountain, adorned with weathered carvings, murmurs softly, adding to the tranquil atmosphere. In the background, the towers of an ancient cathedral rise, capturing the first rays of sunlight that paint the sky in soft pinks and oranges. This image should convey a sense of tranquility, beauty, and a deep connection to the past, celebrating the rich history and timeless charm of the ancient village or town."]
30
  ],
31
+ live=True
32
  )
33
 
34
  # Ejecutar la interfaz