Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import requests
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
# Hugging Face Model API URL
|
| 6 |
+
HF_MODEL_URL = "https://api-inference.huggingface.co/models/your_model_here"
|
| 7 |
+
HF_API_KEY = "YOUR_HUGGINGFACE_API_KEY"
|
| 8 |
+
|
| 9 |
+
# Function to get the concrete mix design from the Hugging Face model API
|
| 10 |
+
def get_concrete_mix_design(strength, slump, w_c_ratio, coarse_aggregate, fine_aggregate, mix_code):
|
| 11 |
+
# Prepare the payload based on selected mix code
|
| 12 |
+
payload = {
|
| 13 |
+
"inputs": {
|
| 14 |
+
"strength": strength,
|
| 15 |
+
"slump": slump,
|
| 16 |
+
"w_c_ratio": w_c_ratio,
|
| 17 |
+
"coarse_aggregate": coarse_aggregate,
|
| 18 |
+
"fine_aggregate": fine_aggregate,
|
| 19 |
+
"mix_code": mix_code # Add the selected mix design code here
|
| 20 |
+
}
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
headers = {"Authorization": f"Bearer {HF_API_KEY}"}
|
| 24 |
+
response = requests.post(HF_MODEL_URL, headers=headers, json=payload)
|
| 25 |
+
|
| 26 |
+
if response.status_code == 200:
|
| 27 |
+
result = response.json()
|
| 28 |
+
mix_design = result.get('mix_design', 'No design available.')
|
| 29 |
+
return mix_design
|
| 30 |
+
else:
|
| 31 |
+
return "Error in getting mix design. Please try again."
|
| 32 |
+
|
| 33 |
+
# Function to handle the user interface logic
|
| 34 |
+
def concrete_mix_ui(strength, slump, w_c_ratio, coarse_aggregate, fine_aggregate, mix_code):
|
| 35 |
+
# Get the mix design based on the user's input and selected mix code
|
| 36 |
+
mix_design = get_concrete_mix_design(strength, slump, w_c_ratio, coarse_aggregate, fine_aggregate, mix_code)
|
| 37 |
+
|
| 38 |
+
# Format the output
|
| 39 |
+
if isinstance(mix_design, dict): # Check if we received valid data
|
| 40 |
+
return f"Recommended Concrete Mix Design (Using {mix_code}):\n\n" \
|
| 41 |
+
f"- Cement: {mix_design.get('cement', 'N/A')} kg/m³\n" \
|
| 42 |
+
f"- Water: {mix_design.get('water', 'N/A')} liters/m³\n" \
|
| 43 |
+
f"- Fine Aggregate: {mix_design.get('fine_aggregate', 'N/A')} kg/m³\n" \
|
| 44 |
+
f"- Coarse Aggregate: {mix_design.get('coarse_aggregate', 'N/A')} kg/m³\n" \
|
| 45 |
+
f"- Admixture: {mix_design.get('admixture', 'N/A')} liters/m³\n" \
|
| 46 |
+
f"- Water-Cement Ratio: {mix_design.get('w_c_ratio', 'N/A')}\n" \
|
| 47 |
+
f"- Strength: {mix_design.get('strength', 'N/A')} MPa"
|
| 48 |
+
else:
|
| 49 |
+
return mix_design # If the design is not available, return the error message
|
| 50 |
+
|
| 51 |
+
# User Interface: Define the input components
|
| 52 |
+
inputs = [
|
| 53 |
+
gr.Slider(minimum=20, maximum=60, step=1, label="Compressive Strength (MPa)", value=30),
|
| 54 |
+
gr.Slider(minimum=0, maximum=250, step=5, label="Slump (mm)", value=100),
|
| 55 |
+
gr.Slider(minimum=0.3, maximum=0.7, step=0.01, label="Water-Cement Ratio", value=0.5),
|
| 56 |
+
gr.Slider(minimum=100, maximum=1000, step=10, label="Coarse Aggregate (kg/m³)", value=600),
|
| 57 |
+
gr.Slider(minimum=100, maximum=1000, step=10, label="Fine Aggregate (kg/m³)", value=500),
|
| 58 |
+
gr.Dropdown(choices=["IS 456", "ACI", "BS", "Other"], label="Select Mix Design Code", value="IS 456")
|
| 59 |
+
]
|
| 60 |
+
|
| 61 |
+
# Output component to display the result
|
| 62 |
+
output = gr.Textbox(label="Concrete Mix Design Output", interactive=False)
|
| 63 |
+
|
| 64 |
+
# Build the Gradio interface
|
| 65 |
+
interface = gr.Interface(
|
| 66 |
+
fn=concrete_mix_ui,
|
| 67 |
+
inputs=inputs,
|
| 68 |
+
outputs=output,
|
| 69 |
+
title="Concrete Mix Design Calculator",
|
| 70 |
+
description="Enter your concrete mix parameters and select the appropriate mix design code to get the best mix design.",
|
| 71 |
+
live=True,
|
| 72 |
+
theme="compact",
|
| 73 |
+
)
|
| 74 |
+
|
| 75 |
+
# Launch the app
|
| 76 |
+
interface.launch(share=True)
|