Spaces:
Sleeping
Sleeping
File size: 2,834 Bytes
99708e7 bcd1227 99708e7 bcd1227 99708e7 bcd1227 99708e7 8fc03c2 99708e7 8fc03c2 99708e7 8fc03c2 bcd1227 8fc03c2 99708e7 8fc03c2 99708e7 8fc03c2 99708e7 8fc03c2 bcd1227 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
import gradio as gr
import requests
# Using a general-purpose model hosted on Hugging Face
HF_MODEL_URL = "https://api-inference.huggingface.co/models/distilbert-base-uncased"
HF_API_KEY = "YOUR_HUGGINGFACE_API_KEY" # Make sure your API key is valid
# Function to get a response from the Hugging Face model API
def get_concrete_mix_design(strength, slump, w_c_ratio, coarse_aggregate, fine_aggregate, mix_code):
payload = {
"inputs": {
"text": f"Strength: {strength} MPa, Slump: {slump} mm, Water-Cement Ratio: {w_c_ratio}, "
f"Coarse Aggregate: {coarse_aggregate} kg/m³, Fine Aggregate: {fine_aggregate} kg/m³, "
f"Mix Code: {mix_code}"
}
}
headers = {"Authorization": f"Bearer {HF_API_KEY}"}
try:
response = requests.post(HF_MODEL_URL, headers=headers, json=payload)
response.raise_for_status() # Raise an HTTPError for bad responses (4xx, 5xx)
if response.status_code == 200:
result = response.json()
generated_text = result.get('generated_text', 'No response from model.')
return generated_text
else:
return f"Error: Received status code {response.status_code}. Response: {response.text}"
except requests.exceptions.RequestException as e:
return f"Request failed: {e}"
# Function to handle the user interface logic
def concrete_mix_ui(strength, slump, w_c_ratio, coarse_aggregate, fine_aggregate, mix_code):
# Get the mix design based on the user's input and selected mix code
mix_design = get_concrete_mix_design(strength, slump, w_c_ratio, coarse_aggregate, fine_aggregate, mix_code)
return mix_design
# User Interface: Define the input components
inputs = [
gr.Slider(minimum=20, maximum=60, step=1, label="Compressive Strength (MPa)", value=30),
gr.Slider(minimum=0, maximum=250, step=5, label="Slump (mm)", value=100),
gr.Slider(minimum=0.3, maximum=0.7, step=0.01, label="Water-Cement Ratio", value=0.5),
gr.Slider(minimum=100, maximum=1000, step=10, label="Coarse Aggregate (kg/m³)", value=600),
gr.Slider(minimum=100, maximum=1000, step=10, label="Fine Aggregate (kg/m³)", value=500),
gr.Dropdown(choices=["IS 456", "ACI", "BS", "Other"], label="Select Mix Design Code", value="IS 456")
]
# Output component to display the result
output = gr.Textbox(label="Concrete Mix Design Output", interactive=False)
# Build the Gradio interface
interface = gr.Interface(
fn=concrete_mix_ui,
inputs=inputs,
outputs=output,
title="Concrete Mix Design Calculator",
description="Enter your concrete mix parameters and select the appropriate mix design code to get the best mix design.",
live=True,
theme="compact",
)
# Launch the app with public link
interface.launch(share=True)
|