| import gradio as gr |
| import pandas as pd |
| import numpy as np |
|
|
| |
| |
| |
| |
| |
|
|
| try: |
| model = joblib.load("biomass_model.pkl") |
| model_loaded = True |
| except: |
| model_loaded = False |
|
|
|
|
| |
| |
| |
| def predict_composition(cellulose, hemicellulose, lignin, moisture, ash): |
|
|
| |
| input_data = np.array([ |
| [cellulose, hemicellulose, lignin, moisture, ash] |
| ]) |
|
|
| |
| if model_loaded: |
| prediction = model.predict(input_data) |
|
|
| return { |
| "Predicted Biomass Composition": float(prediction[0]) |
| } |
|
|
| |
| biomass_score = ( |
| 0.35 * cellulose + |
| 0.25 * hemicellulose + |
| 0.20 * lignin - |
| 0.10 * moisture - |
| 0.10 * ash |
| ) |
|
|
| return { |
| "Estimated Biomass Score": round(biomass_score, 2) |
| } |
|
|
|
|
| |
| |
| |
| with gr.Blocks(theme=gr.themes.Soft()) as demo: |
|
|
| gr.Markdown( |
| """ |
| # Biomass Composition Finder |
| |
| Enter biomass properties to estimate biomass composition. |
| """ |
| ) |
|
|
| with gr.Row(): |
| cellulose = gr.Slider(0, 100, value=40, label="Cellulose (%)") |
| hemicellulose = gr.Slider(0, 100, value=25, label="Hemicellulose (%)") |
|
|
| with gr.Row(): |
| lignin = gr.Slider(0, 100, value=20, label="Lignin (%)") |
| moisture = gr.Slider(0, 100, value=10, label="Moisture Content (%)") |
|
|
| ash = gr.Slider(0, 50, value=5, label="Ash Content (%)") |
|
|
| output = gr.JSON(label="Prediction Result") |
|
|
| predict_btn = gr.Button("Predict") |
|
|
| predict_btn.click( |
| fn=predict_composition, |
| inputs=[ |
| cellulose, |
| hemicellulose, |
| lignin, |
| moisture, |
| ash |
| ], |
| outputs=output |
| ) |
|
|
|
|
| |
| |
| |
| demo.launch() |