iYuri commited on
Commit
017a0b8
·
verified ·
1 Parent(s): bc70d2a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -11
app.py CHANGED
@@ -2,17 +2,25 @@ import gradio as gr
2
  from huggingface_hub import InferenceClient
3
  import os
4
 
5
- # Puxa o token que você acabou de salvar
6
  token = os.getenv("HF_TOKEN")
7
  client = InferenceClient(token=token)
8
 
9
  def gerar_midia(prompt):
10
  try:
11
- # Gera a Imagem (Modelo FLUX - o melhor atual)
12
- imagem = client.text_to_image(prompt, model="black-forest-labs/FLUX.1-schnell")
 
 
 
 
13
 
14
- # Gera o Vídeo (Modelo LTX-Video)
15
- video_bytes = client.text_to_video(prompt, model="Lightricks/LTX-Video")
 
 
 
 
16
 
17
  video_path = "video_resultado.mp4"
18
  with open(video_path, "wb") as f:
@@ -21,18 +29,21 @@ def gerar_midia(prompt):
21
  return imagem, video_path
22
 
23
  except Exception as e:
24
- print(f"Erro: {e}")
 
25
  return None, None
26
 
27
- with gr.Blocks() as demo:
28
- gr.Markdown("# 🚀 Gerador AI: Imagem + Vídeo")
29
- prompt = gr.Textbox(label="O que você quer criar?", placeholder="Ex: Um gato jogando poker...")
30
- btn = gr.Button("Gerar Magia ✨")
 
 
31
 
32
  with gr.Row():
33
  img_out = gr.Image(label="Imagem")
34
  vid_out = gr.Video(label="Vídeo")
35
 
36
- btn.click(fn=gerar_midia, inputs=prompt, outputs=[img_out, vid_out])
37
 
38
  demo.launch()
 
2
  from huggingface_hub import InferenceClient
3
  import os
4
 
5
+ # Puxa o seu token que você salvou no Secret
6
  token = os.getenv("HF_TOKEN")
7
  client = InferenceClient(token=token)
8
 
9
  def gerar_midia(prompt):
10
  try:
11
+ # GERANDO IMAGEM (Usando o modelo estável do Hugging Face)
12
+ print("Gerando imagem...")
13
+ imagem = client.text_to_image(
14
+ prompt,
15
+ model="stabilityai/stable-diffusion-3.5-large-turbo"
16
+ )
17
 
18
+ # GERANDO VÍDEO (Usando o modelo nativo do Hugging Face)
19
+ print("Gerando vídeo...")
20
+ video_bytes = client.text_to_video(
21
+ prompt,
22
+ model="ali-vilab/text-to-video-ms-1.7b"
23
+ )
24
 
25
  video_path = "video_resultado.mp4"
26
  with open(video_path, "wb") as f:
 
29
  return imagem, video_path
30
 
31
  except Exception as e:
32
+ print(f"Erro detalhado: {e}")
33
+ # Se der erro 401 aqui, é porque o token ainda está sendo propagado
34
  return None, None
35
 
36
+ # Interface Gradio
37
+ with gr.Blocks(theme=gr.themes.Soft()) as demo:
38
+ gr.Markdown("# 🚀 Gerador AI Grátis (Imagem + Vídeo)")
39
+ with gr.Row():
40
+ txt = gr.Textbox(label="Seu Prompt", placeholder="Ex: Um gato de óculos escuros na praia")
41
+ btn = gr.Button("GERAR ✨", variant="primary")
42
 
43
  with gr.Row():
44
  img_out = gr.Image(label="Imagem")
45
  vid_out = gr.Video(label="Vídeo")
46
 
47
+ btn.click(fn=gerar_midia, inputs=txt, outputs=[img_out, vid_out])
48
 
49
  demo.launch()