import streamlit as st import requests # Título de la aplicación st.title("Predicción de Cáncer Cervical") # Crear las tres columnas col1, col2, col3 = st.columns(3) # Columna 1 with col1: behavior_sexualRisk = st.number_input("Risk Behavior (Sexual)", min_value=0.0, max_value=100.0, value=10.0) behavior_eating = st.number_input("Eating Behavior", min_value=0.0, max_value=100.0, value=10.0) behavior_personalHygine = st.number_input("Personal Hygiene", min_value=0.0, max_value=100.0, value=10.0) intention_aggregation = st.number_input("Intention Aggregation", min_value=0.0, max_value=100.0, value=10.0) intention_commitment = st.number_input("Intention Commitment", min_value=0.0, max_value=100.0, value=10.0) # Columna 2 with col2: attitude_consistency = st.number_input("Attitude Consistency", min_value=0.0, max_value=100.0, value=10.0) attitude_spontaneity = st.number_input("Attitude Spontaneity", min_value=0.0, max_value=100.0, value=0.0) norm_significantPerson = st.number_input("Norm Significant Person", min_value=0.0, max_value=100.0, value=0.0) norm_fulfillment = st.number_input("Norm Fulfillment", min_value=0.0, max_value=100.0, value=0.0) perception_vulnerability = st.number_input("Perception Vulnerability", min_value=0.0, max_value=100.0, value=0.0) # Columna 3 with col3: perception_severity = st.number_input("Perception Severity", min_value=0.0, max_value=100.0, value=0.0) motivation_strength = st.number_input("Motivation Strength", min_value=0.0, max_value=100.0, value=0.34) motivation_willingness = st.number_input("Motivation Willingness", min_value=0.0, max_value=100.0, value=0.54) socialSupport_emotionality = st.number_input("Social Support Emotionality", min_value=0.0, max_value=100.0, value=0.0) socialSupport_appreciation = st.number_input("Social Support Appreciation", min_value=0.0, max_value=100.0, value=0.0) # Campos adicionales fuera de las columnas empowerment_knowledge = st.number_input("Empowerment Knowledge", min_value=0.0, max_value=100.0, value=10.0) empowerment_abilities = st.number_input("Empowerment Abilities", min_value=0.0, max_value=100.0, value=20.0) empowerment_desires = st.number_input("Empowerment Desires", min_value=0.0, max_value=100.0, value=0.0) # Botón para hacer la predicción if st.button("Obtener Diagnóstico"): # Crear el payload para la solicitud payload = { "behavior_sexualRisk": behavior_sexualRisk, "behavior_eating": behavior_eating, "behavior_personalHygine": behavior_personalHygine, "intention_aggregation": intention_aggregation, "intention_commitment": intention_commitment, "attitude_consistency": attitude_consistency, "attitude_spontaneity": attitude_spontaneity, "norm_significantPerson": norm_significantPerson, "norm_fulfillment": norm_fulfillment, "perception_vulnerability": perception_vulnerability, "perception_severity": perception_severity, "motivation_strength": motivation_strength, "motivation_willingness": motivation_willingness, "socialSupport_emotionality": socialSupport_emotionality, "socialSupport_appreciation": socialSupport_appreciation, "socialSupport_instrumental": 0, # Este campo no lo envías en el formulario pero lo necesitas "empowerment_knowledge": empowerment_knowledge, "empowerment_abilities": empowerment_abilities, "empowerment_desires": empowerment_desires } # Hacer la solicitud a la API url = 'https://jairodanielmt-ejemplo-anibal.hf.space/predict/' headers = {'Content-Type': 'application/json', 'Accept': 'application/json'} try: response = requests.post(url, json=payload, headers=headers) response.raise_for_status() # Lanza un error si el código de estado no es 200 # Verificar si la respuesta es exitosa result = response.json() # Asumiendo que la respuesta contiene una clave 'ca_cervix_prediction' ca_cervix_prediction = result.get('ca_cervix_prediction', 'No disponible') # Mostrar el diagnóstico recibido st.success(f"Diagnóstico: {ca_cervix_prediction}") except requests.exceptions.HTTPError as http_err: st.error(f"Error HTTP: {http_err}") except Exception as err: st.error(f"Error: {err}")