Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| from huggingface_hub import InferenceClient | |
| import io | |
| from PIL import Image | |
| # 1. Configuração da Página | |
| st.set_page_config(page_title="PoseMaster AI v3.2", layout="centered") | |
| # 2. Estilização Visual (Dark Mode) | |
| st.markdown(""" | |
| <style> | |
| .main { background-color: #0e1117; color: white; } | |
| .pose-card { | |
| background-color: #1e1e1e; | |
| padding: 20px; | |
| border-radius: 15px; | |
| border-left: 5px solid #00ffcc; | |
| margin-bottom: 20px; | |
| } | |
| .stButton>button { | |
| background-color: #00ffcc; | |
| color: black; | |
| font-weight: bold; | |
| width: 100%; | |
| border-radius: 8px; | |
| } | |
| </style> | |
| """, unsafe_allow_html=True) | |
| st.title("📸 PoseMaster AI") | |
| st.write("Gere descrições técnicas e referências visuais sem custos.") | |
| # 3. Barra Lateral (Configurações) | |
| with st.sidebar: | |
| st.header("🔑 Configuração") | |
| hf_token = st.text_input("Seu Hugging Face Token:", type="password") | |
| st.info("Pegue seu token em: Settings > Access Tokens no Hugging Face.") | |
| # 4. Interface de Usuário | |
| contexto = st.text_area("Descreva o ensaio (Ex: Modelo na floresta, luz de manhã, vestido branco):") | |
| estilo = st.selectbox("Estilo Visual", ["Editorial de Moda", "Retrato Casual", "Street Photography", "Cinematográfico"]) | |
| if st.button("Gerar Guia de Pose"): | |
| if not hf_token: | |
| st.error("Por favor, insira o seu Token na barra lateral!") | |
| else: | |
| try: | |
| client = InferenceClient(token=hf_token) | |
| # --- PARTE 1: GERAÇÃO DA DESCRIÇÃO (TEXTO) --- | |
| with st.spinner('🧠 IA criando a descrição da pose...'): | |
| messages = [ | |
| {"role": "system", "content": "Você é um diretor de fotografia. Sugira uma pose detalhada em Português. Seja breve e técnico."}, | |
| {"role": "user", "content": f"Sugira uma pose para: {contexto}. Estilo: {estilo}"} | |
| ] | |
| text_res = client.chat_completion( | |
| model="meta-llama/Meta-Llama-3-8B-Instruct", | |
| messages=messages, | |
| max_tokens=250 | |
| ) | |
| descricao_pose = text_res.choices[0].message.content | |
| st.markdown("### 📝 Descrição Técnica") | |
| st.markdown(f"<div class='pose-card'>{descricao_pose}</div>", unsafe_allow_html=True) | |
| # --- PARTE 2: GERAÇÃO DA REFERÊNCIA (IMAGEM) --- | |
| with st.spinner('🎨 Renderizando imagem de referência...'): | |
| # Prompt otimizado para IA de imagem (em inglês funciona melhor) | |
| image_prompt = f"Professional photography, {estilo}, full body human pose, {descricao_pose}, highly detailed, realistic, 8k" | |
| # Usando um modelo de comunidade estável e gratuito | |
| image_bytes = client.text_to_image( | |
| image_prompt, | |
| model="Lykon/AnyLoRA" | |
| ) | |
| image = Image.open(io.BytesIO(image_bytes)) | |
| st.image(image, caption="Sua Referência Visual", use_container_width=True) | |
| st.success("Pose gerada com sucesso!") | |
| except Exception as e: | |
| if "402" in str(e): | |
| st.error("Erro: O modelo atual tornou-se pago. Tente novamente em instantes ou me peça para trocar o modelo.") | |
| else: | |
| st.error(f"Ocorreu um erro: {e}") | |
| st.divider() | |
| st.caption("PoseMaster AI - Foco em Narrativa e Impacto Visual.") |