MuhammadHananKhan123 commited on
Commit
bf8e026
·
verified ·
1 Parent(s): 7bd836c

requirements.txt

Browse files

gradio
pandas
numpy
joblib
scikit-learn

Files changed (1) hide show
  1. app.py +94 -0
app.py ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pandas as pd
3
+ import joblib
4
+ import numpy as np
5
+
6
+ # =========================================================
7
+ # Load trained model
8
+ # =========================================================
9
+ # Upload your trained model file in the same Hugging Face Space
10
+ # Example model name: biomass_model.pkl
11
+
12
+ try:
13
+ model = joblib.load("biomass_model.pkl")
14
+ model_loaded = True
15
+ except:
16
+ model_loaded = False
17
+
18
+
19
+ # =========================================================
20
+ # Prediction Function
21
+ # =========================================================
22
+ def predict_composition(cellulose, hemicellulose, lignin, moisture, ash):
23
+
24
+ # Input array
25
+ input_data = np.array([
26
+ [cellulose, hemicellulose, lignin, moisture, ash]
27
+ ])
28
+
29
+ # If model exists
30
+ if model_loaded:
31
+ prediction = model.predict(input_data)
32
+
33
+ return {
34
+ "Predicted Biomass Composition": float(prediction[0])
35
+ }
36
+
37
+ # Dummy calculation if model not uploaded yet
38
+ biomass_score = (
39
+ 0.35 * cellulose +
40
+ 0.25 * hemicellulose +
41
+ 0.20 * lignin -
42
+ 0.10 * moisture -
43
+ 0.10 * ash
44
+ )
45
+
46
+ return {
47
+ "Estimated Biomass Score": round(biomass_score, 2)
48
+ }
49
+
50
+
51
+ # =========================================================
52
+ # Gradio Interface
53
+ # =========================================================
54
+ with gr.Blocks(theme=gr.themes.Soft()) as demo:
55
+
56
+ gr.Markdown(
57
+ """
58
+ # Biomass Composition Finder
59
+
60
+ Enter biomass properties to estimate biomass composition.
61
+ """
62
+ )
63
+
64
+ with gr.Row():
65
+ cellulose = gr.Slider(0, 100, value=40, label="Cellulose (%)")
66
+ hemicellulose = gr.Slider(0, 100, value=25, label="Hemicellulose (%)")
67
+
68
+ with gr.Row():
69
+ lignin = gr.Slider(0, 100, value=20, label="Lignin (%)")
70
+ moisture = gr.Slider(0, 100, value=10, label="Moisture Content (%)")
71
+
72
+ ash = gr.Slider(0, 50, value=5, label="Ash Content (%)")
73
+
74
+ output = gr.JSON(label="Prediction Result")
75
+
76
+ predict_btn = gr.Button("Predict")
77
+
78
+ predict_btn.click(
79
+ fn=predict_composition,
80
+ inputs=[
81
+ cellulose,
82
+ hemicellulose,
83
+ lignin,
84
+ moisture,
85
+ ash
86
+ ],
87
+ outputs=output
88
+ )
89
+
90
+
91
+ # =========================================================
92
+ # Launch App
93
+ # =========================================================
94
+ demo.launch()