# app.py import os import sys import json # Add current dir to path (for local/HF compatibility) sys.path.append(os.path.dirname(__file__)) # Import the function we just defined from crew import run_crew_for_ride import gradio as gr def predict_ride_api(rideID: str): """ API endpoint for Uber ride success prediction. Input: rideID (str) Output: JSON dict (prediction, confidence, features, etc.) """ if not rideID or not rideID.strip(): return {"status": "error", "message": "rideID is required"} rideID = rideID.strip() result = run_crew_for_ride(rideID) return result # Gradio UI with gr.Blocks(theme=gr.themes.Soft()) as demo: gr.Markdown("# 🚖 Uber Ride Success Predictor (CrewAI + Gradient Boosting)") gr.Markdown("Enter a ride ID (e.g., `CNR1000732`) to get ML-based prediction and summary.") ride_id_input = gr.Textbox( label="Ride ID", placeholder="e.g., CNR1000732", value="CNR1000732" # optional default for demo ) output = gr.JSON(label="Prediction Result") btn = gr.Button("Run Prediction", variant="primary") btn.click( fn=predict_ride_api, inputs=ride_id_input, outputs=output ) gr.Markdown("💡 Behind the scenes: Gradient Boosting model + Llama3.1 for explanation + Firebase sync.") # Launch for HF Spaces demo.launch()