Spaces:
Runtime error
Runtime error
Download app.py from douglasribeiro/classes_vpl: direct link, hf CLI and curl.
- Browser
- Download file 1.49 kB
-
https://huggingface.co/spaces/douglasribeiro/classes_vpl/resolve/main/app.py
- Command line
-
hf download hf://spaces/douglasribeiro/classes_vpl/app.py
-
curl -L -o app.py https://huggingface.co/spaces/douglasribeiro/classes_vpl/resolve/main/app.py
1.49 kB
| import gradio as gr | |
| import numpy as np | |
| import tensorflow as tf | |
| import joblib | |
| # Carregar modelo e scaler ajustado | |
| modelo = tf.keras.models.load_model("modelo_vpl.h5") | |
| scaler = joblib.load("scaler_treinado.pkl") | |
| # Função de previsão | |
| def prever_viabilidade(investimento, preco, custo_variavel, demanda_1, demanda_2, demanda_3, demanda_4, demanda_5, selic): | |
| entrada = np.array([[investimento, preco, custo_variavel, demanda_1, demanda_2, demanda_3, demanda_4, demanda_5, selic]]) | |
| entrada_normalizada = scaler.transform(entrada) | |
| previsao = modelo.predict(entrada_normalizada) | |
| return "✅ Viável" if previsao[0][1] > 0.5 else "❌ Não Viável" # [1] assume classe "Viável" está no índice 1 | |
| # Interface Gradio | |
| interface = gr.Interface( | |
| fn=prever_viabilidade, | |
| inputs=[ | |
| gr.Number(label="Investimento Inicial"), | |
| gr.Number(label="Preço por Unidade"), | |
| gr.Number(label="Custo Variável por Unidade"), | |
| gr.Number(label="Demanda Ano 1"), | |
| gr.Number(label="Demanda Ano 2"), | |
| gr.Number(label="Demanda Ano 3"), | |
| gr.Number(label="Demanda Ano 4"), | |
| gr.Number(label="Demanda Ano 5"), | |
| gr.Number(label="Taxa Selic (%)"), | |
| ], | |
| outputs=gr.Text(label="Resultado da Viabilidade"), | |
| title="Simulador de Viabilidade Econômica com MLP", | |
| description="Este aplicativo prevê se um projeto é financeiramente viável com base nas premissas fornecidas.", | |
| ) | |
| if __name__ == "__main__": | |
| interface.launch() | |