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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import numpy as np
|
| 3 |
+
|
| 4 |
+
# A placeholder function to simulate the Authencoder model's prediction.
|
| 5 |
+
# Replace this with your actual model's prediction function.
|
| 6 |
+
# This function demonstrates how to take all the inputs and return an output.
|
| 7 |
+
# You will need to load your model here and perform the actual inference.
|
| 8 |
+
def predict_quality(
|
| 9 |
+
herb_name,
|
| 10 |
+
temperature,
|
| 11 |
+
humidity,
|
| 12 |
+
storage_time,
|
| 13 |
+
light_exposure,
|
| 14 |
+
soil_ph,
|
| 15 |
+
soil_moisture,
|
| 16 |
+
soil_nitrogen,
|
| 17 |
+
soil_phosphorus,
|
| 18 |
+
soil_potassium,
|
| 19 |
+
soil_organic_carbon,
|
| 20 |
+
heavy_metal_pb,
|
| 21 |
+
heavy_metal_as,
|
| 22 |
+
heavy_metal_hg,
|
| 23 |
+
heavy_metal_cd,
|
| 24 |
+
aflatoxin_total,
|
| 25 |
+
pesticide_residue_total,
|
| 26 |
+
moisture_content,
|
| 27 |
+
essential_oil,
|
| 28 |
+
chlorophyll_index,
|
| 29 |
+
leaf_spots_count,
|
| 30 |
+
discoloration_index,
|
| 31 |
+
total_bacterial_count,
|
| 32 |
+
total_fungal_count,
|
| 33 |
+
e_coli_present,
|
| 34 |
+
salmonella_present,
|
| 35 |
+
dna_marker_authenticity
|
| 36 |
+
):
|
| 37 |
+
"""
|
| 38 |
+
This function simulates a model's prediction based on the input parameters.
|
| 39 |
+
In a real application, you would load and use your Authencoder model here.
|
| 40 |
+
|
| 41 |
+
Args:
|
| 42 |
+
All the parameters from the Gradio form.
|
| 43 |
+
|
| 44 |
+
Returns:
|
| 45 |
+
A string with a simulated quality prediction.
|
| 46 |
+
"""
|
| 47 |
+
# Placeholder logic:
|
| 48 |
+
# This is a dummy response. Replace this with your model's actual
|
| 49 |
+
# inference code. For example:
|
| 50 |
+
#
|
| 51 |
+
# from transformers import pipeline
|
| 52 |
+
# model = pipeline("your-model-task", model="your-model-id")
|
| 53 |
+
# result = model(your_processed_input_data)
|
| 54 |
+
#
|
| 55 |
+
# For this example, we'll just check a few parameters to give a meaningful
|
| 56 |
+
# placeholder output.
|
| 57 |
+
|
| 58 |
+
quality_score = np.random.uniform(70, 100)
|
| 59 |
+
|
| 60 |
+
# Check for critical parameters
|
| 61 |
+
if e_coli_present == "Yes" or salmonella_present == "Yes":
|
| 62 |
+
return f"Warning: E. coli or Salmonella detected. Quality is 'Unsafe'."
|
| 63 |
+
|
| 64 |
+
if heavy_metal_cd > 0.5 or heavy_metal_hg > 0.5:
|
| 65 |
+
return f"Warning: High heavy metal content. Quality is 'Poor'."
|
| 66 |
+
|
| 67 |
+
if moisture_content > 10 or total_bacterial_count > 1000:
|
| 68 |
+
quality_score -= 20
|
| 69 |
+
|
| 70 |
+
if dna_marker_authenticity == "No":
|
| 71 |
+
return f"Warning: Authenticity not confirmed by DNA marker. Quality is 'Unverified'."
|
| 72 |
+
|
| 73 |
+
return f"Based on the provided data, the quality of {herb_name} is 'Good' with a score of {quality_score:.2f}/100."
|
| 74 |
+
|
| 75 |
+
# Create the Gradio Interface
|
| 76 |
+
with gr.Blocks(title="Authencoder Herb Quality Assessment") as app:
|
| 77 |
+
gr.Markdown(
|
| 78 |
+
"""
|
| 79 |
+
# Authencoder: Herb Quality Assessment
|
| 80 |
+
This application simulates a system for assessing the quality and authenticity of herbs based on various parameters.
|
| 81 |
+
**Note**: This is a demo. Please replace the `predict_quality` function with your actual model's inference logic.
|
| 82 |
+
"""
|
| 83 |
+
)
|
| 84 |
+
with gr.Row():
|
| 85 |
+
with gr.Column():
|
| 86 |
+
gr.Markdown("### Herb Details and Environmental Factors")
|
| 87 |
+
herb_name = gr.Textbox(label="Herb Name", placeholder="e.g., Turmeric, Ginseng")
|
| 88 |
+
temperature = gr.Slider(minimum=-10, maximum=50, step=0.1, label="Temperature ($^\circ C$)", value=25)
|
| 89 |
+
humidity = gr.Slider(minimum=0, maximum=100, step=0.1, label="Humidity (%)", value=60)
|
| 90 |
+
storage_time = gr.Number(label="Storage Time (Days)", value=30)
|
| 91 |
+
light_exposure = gr.Slider(minimum=0, maximum=24, step=0.1, label="Light Exposure (hours per day)", value=8)
|
| 92 |
+
|
| 93 |
+
with gr.Column():
|
| 94 |
+
gr.Markdown("### Soil and Chemical Analysis")
|
| 95 |
+
soil_ph = gr.Slider(minimum=0, maximum=14, step=0.1, label="Soil pH", value=6.5)
|
| 96 |
+
soil_moisture = gr.Slider(minimum=0, maximum=100, step=0.1, label="Soil Moisture (%)", value=50)
|
| 97 |
+
soil_nitrogen = gr.Number(label="Soil Nitrogen (mg/kg)", value=100)
|
| 98 |
+
soil_phosphorus = gr.Number(label="Soil Phosphorus (mg/kg)", value=50)
|
| 99 |
+
soil_potassium = gr.Number(label="Soil Potassium (mg/kg)", value=200)
|
| 100 |
+
soil_organic_carbon = gr.Number(label="Soil Organic Carbon (%)", value=2.5)
|
| 101 |
+
|
| 102 |
+
with gr.Column():
|
| 103 |
+
gr.Markdown("### Heavy Metals, Toxins, and Pesticides")
|
| 104 |
+
heavy_metal_pb = gr.Number(label="Heavy Metal Pb (ppm)", value=0.1)
|
| 105 |
+
heavy_metal_as = gr.Number(label="Heavy Metal As (ppm)", value=0.05)
|
| 106 |
+
heavy_metal_hg = gr.Number(label="Heavy Metal Hg (ppm)", value=0.01)
|
| 107 |
+
heavy_metal_cd = gr.Number(label="Heavy Metal Cd (ppm)", value=0.01)
|
| 108 |
+
aflatoxin_total = gr.Number(label="Aflatoxin Total (ppb)", value=0.2)
|
| 109 |
+
pesticide_residue_total = gr.Number(label="Pesticide Residue Total (ppm)", value=0.03)
|
| 110 |
+
|
| 111 |
+
with gr.Row():
|
| 112 |
+
with gr.Column():
|
| 113 |
+
gr.Markdown("### Physical and Biological Traits")
|
| 114 |
+
moisture_content = gr.Slider(minimum=0, maximum=100, step=0.1, label="Moisture Content (%)", value=8)
|
| 115 |
+
essential_oil = gr.Slider(minimum=0, maximum=100, step=0.1, label="Essential Oil (%)", value=2)
|
| 116 |
+
chlorophyll_index = gr.Number(label="Chlorophyll Index", value=0.7)
|
| 117 |
+
leaf_spots_count = gr.Number(label="Leaf Spots Count", value=5)
|
| 118 |
+
discoloration_index = gr.Slider(minimum=0, maximum=100, step=0.1, label="Discoloration Index (%)", value=15)
|
| 119 |
+
|
| 120 |
+
with gr.Column():
|
| 121 |
+
gr.Markdown("### Microbial and Authenticity Checks")
|
| 122 |
+
total_bacterial_count = gr.Number(label="Total Bacterial Count (CFU/g)", value=500)
|
| 123 |
+
total_fungal_count = gr.Number(label="Total Fungal Count (CFU/g)", value=100)
|
| 124 |
+
e_coli_present = gr.Radio(choices=["Yes", "No"], label="E. coli Present", value="No")
|
| 125 |
+
salmonella_present = gr.Radio(choices=["Yes", "No"], label="Salmonella Present", value="No")
|
| 126 |
+
dna_marker_authenticity = gr.Radio(choices=["Yes", "No"], label="DNA Marker Authenticity", value="Yes")
|
| 127 |
+
|
| 128 |
+
submit_btn = gr.Button("Assess Quality", variant="primary")
|
| 129 |
+
output_text = gr.Text(label="Assessment Result")
|
| 130 |
+
|
| 131 |
+
submit_btn.click(
|
| 132 |
+
fn=predict_quality,
|
| 133 |
+
inputs=[
|
| 134 |
+
herb_name,
|
| 135 |
+
temperature,
|
| 136 |
+
humidity,
|
| 137 |
+
storage_time,
|
| 138 |
+
light_exposure,
|
| 139 |
+
soil_ph,
|
| 140 |
+
soil_moisture,
|
| 141 |
+
soil_nitrogen,
|
| 142 |
+
soil_phosphorus,
|
| 143 |
+
soil_potassium,
|
| 144 |
+
soil_organic_carbon,
|
| 145 |
+
heavy_metal_pb,
|
| 146 |
+
heavy_metal_as,
|
| 147 |
+
heavy_metal_hg,
|
| 148 |
+
heavy_metal_cd,
|
| 149 |
+
aflatoxin_total,
|
| 150 |
+
pesticide_residue_total,
|
| 151 |
+
moisture_content,
|
| 152 |
+
essential_oil,
|
| 153 |
+
chlorophyll_index,
|
| 154 |
+
leaf_spots_count,
|
| 155 |
+
discoloration_index,
|
| 156 |
+
total_bacterial_count,
|
| 157 |
+
total_fungal_count,
|
| 158 |
+
e_coli_present,
|
| 159 |
+
salmonella_present,
|
| 160 |
+
dna_marker_authenticity
|
| 161 |
+
],
|
| 162 |
+
outputs=output_text
|
| 163 |
+
)
|
| 164 |
+
|
| 165 |
+
app.launch()
|