import gradio as gr import requests API_KEY = "a4a08533db7145488ca0b2d73268496f" def generate_womens_health_advice(age, cycle_length, pregnancy_status, additional_concerns): # Construct the user message using the new input fields. user_message = ( f"Age: {age}, Cycle Length: {cycle_length} days, " f"Pregnancy Status: {pregnancy_status}, Concerns: {additional_concerns}." ) # Update the system message to reflect the women's health guide domain. system_message = ( "You are an AI women's health guide. Track menstrual cycles, pregnancy, " "and overall reproductive health. Provide tailored advice and insights." ) payload = { "model": "deepseek-ai/deepseek-llm-67b-chat", "messages": [ {"role": "system", "content": system_message}, {"role": "user", "content": user_message} ] } headers = { "Authorization": f"Bearer {API_KEY}", "Content-Type": "application/json" } try: response = requests.post("https://api.aimlapi.com/v1/chat/completions", json=payload, headers=headers) response.raise_for_status() message = response.json()["choices"][0]["message"]["content"] return message except Exception as e: try: error_details = response.json() except Exception: error_details = response.text return f"Error: {str(e)}. Details: {error_details}" # Update the Gradio UI with fields relevant to women's health. iface = gr.Interface( fn=generate_womens_health_advice, inputs=[ gr.Number(label="Age", value=25, precision=0), gr.Number(label="Average Menstrual Cycle Length (days)", value=28, precision=0), gr.Dropdown(choices=["Not Pregnant", "Pregnant", "Postpartum", "Trying to conceive"], label="Pregnancy Status", value="Not Pregnant"), gr.Textbox(lines=2, placeholder="Any additional reproductive health concerns?", label="Additional Concerns") ], outputs="text", title="Women's Health Guide: Reproductive Health Tracker", description=( "Enter your details to receive tailored advice on tracking your menstrual cycle, " "pregnancy, and overall reproductive health." ) ) if __name__ == "__main__": iface.launch()