Spaces:
Running
Running
| import gradio as gr | |
| from huggingface_hub import InferenceClient | |
| import os | |
| # Puxa o seu token que você salvou no Secret | |
| token = os.getenv("HF_TOKEN") | |
| client = InferenceClient(token=token) | |
| def gerar_midia(prompt): | |
| try: | |
| # GERANDO IMAGEM (Usando o modelo estável do Hugging Face) | |
| print("Gerando imagem...") | |
| imagem = client.text_to_image( | |
| prompt, | |
| model="stabilityai/stable-diffusion-3.5-large-turbo" | |
| ) | |
| # GERANDO VÍDEO (Usando o modelo nativo do Hugging Face) | |
| print("Gerando vídeo...") | |
| video_bytes = client.text_to_video( | |
| prompt, | |
| model="ali-vilab/text-to-video-ms-1.7b" | |
| ) | |
| video_path = "video_resultado.mp4" | |
| with open(video_path, "wb") as f: | |
| f.write(video_bytes) | |
| return imagem, video_path | |
| except Exception as e: | |
| print(f"Erro detalhado: {e}") | |
| # Se der erro 401 aqui, é porque o token ainda está sendo propagado | |
| return None, None | |
| # Interface Gradio | |
| with gr.Blocks(theme=gr.themes.Soft()) as demo: | |
| gr.Markdown("# 🚀 Gerador AI Grátis (Imagem + Vídeo)") | |
| with gr.Row(): | |
| txt = gr.Textbox(label="Seu Prompt", placeholder="Ex: Um gato de óculos escuros na praia") | |
| btn = gr.Button("GERAR ✨", variant="primary") | |
| with gr.Row(): | |
| img_out = gr.Image(label="Imagem") | |
| vid_out = gr.Video(label="Vídeo") | |
| btn.click(fn=gerar_midia, inputs=txt, outputs=[img_out, vid_out]) | |
| demo.launch() | |