Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from xgboost import XGBRegressor | |
| import numpy as np | |
| # --- Load your trained model --- | |
| model = XGBRegressor() | |
| model.load_model("2context7columns.json") | |
| # --- Function to create sliding windows --- | |
| def create_sliding_windows(input_str, window_size=2): | |
| windows = [input_str[i:i+window_size] for i in range(len(input_str)-window_size+1)] | |
| # Convert to float by prepending 0. | |
| return [float("0." + w) for w in windows] | |
| # --- Function for Gradio --- | |
| def predict_final_answer(input_str): | |
| input_str = input_str.strip() | |
| if len(input_str) != 7 or not input_str.isdigit(): | |
| return "Error: Input must be exactly 7 digits." | |
| # Create sliding windows | |
| features = create_sliding_windows(input_str, window_size=2) | |
| if len(features) != 6: | |
| return "Error: Number of features must be 6 for prediction." | |
| # Convert to 2D array for XGBoost | |
| features_array = np.array(features).reshape(1, -1) | |
| # Predict tier7 | |
| prediction = model.predict(features_array) | |
| ans = f"{prediction[0]:.9f}" | |
| return ans | |
| # --- Gradio Interface --- | |
| iface = gr.Interface( | |
| fn=predict_final_answer, | |
| inputs=gr.Textbox(label="Enter 7-digit string"), | |
| outputs=gr.Textbox(label="Final Answer"), | |
| title="Tier7 Predictor", | |
| description="Enter a 7-digit string to predict tier7 value (returns final digits)." | |
| ) | |
| iface.launch() | |