Spaces:
Sleeping
Sleeping
File size: 1,397 Bytes
56c0820 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | # 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() |