Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,5 @@
|
|
| 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"
|
|
@@ -8,7 +7,6 @@ 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,
|
|
@@ -16,28 +14,28 @@ def get_concrete_mix_design(strength, slump, w_c_ratio, coarse_aggregate, fine_a
|
|
| 16 |
"w_c_ratio": w_c_ratio,
|
| 17 |
"coarse_aggregate": coarse_aggregate,
|
| 18 |
"fine_aggregate": fine_aggregate,
|
| 19 |
-
"mix_code": mix_code
|
| 20 |
}
|
| 21 |
}
|
| 22 |
-
|
| 23 |
headers = {"Authorization": f"Bearer {HF_API_KEY}"}
|
| 24 |
-
|
|
|
|
|
|
|
| 25 |
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
|
|
|
|
|
|
| 32 |
|
| 33 |
-
# Function to
|
| 34 |
-
def
|
| 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" \
|
|
@@ -46,7 +44,13 @@ def concrete_mix_ui(strength, slump, w_c_ratio, coarse_aggregate, fine_aggregate
|
|
| 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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
# User Interface: Define the input components
|
| 52 |
inputs = [
|
|
@@ -72,5 +76,6 @@ interface = gr.Interface(
|
|
| 72 |
theme="compact",
|
| 73 |
)
|
| 74 |
|
| 75 |
-
# Launch the app
|
| 76 |
interface.launch(share=True)
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
|
|
|
| 3 |
|
| 4 |
# Hugging Face Model API URL
|
| 5 |
HF_MODEL_URL = "https://api-inference.huggingface.co/models/your_model_here"
|
|
|
|
| 7 |
|
| 8 |
# Function to get the concrete mix design from the Hugging Face model API
|
| 9 |
def get_concrete_mix_design(strength, slump, w_c_ratio, coarse_aggregate, fine_aggregate, mix_code):
|
|
|
|
| 10 |
payload = {
|
| 11 |
"inputs": {
|
| 12 |
"strength": strength,
|
|
|
|
| 14 |
"w_c_ratio": w_c_ratio,
|
| 15 |
"coarse_aggregate": coarse_aggregate,
|
| 16 |
"fine_aggregate": fine_aggregate,
|
| 17 |
+
"mix_code": mix_code
|
| 18 |
}
|
| 19 |
}
|
| 20 |
+
|
| 21 |
headers = {"Authorization": f"Bearer {HF_API_KEY}"}
|
| 22 |
+
try:
|
| 23 |
+
response = requests.post(HF_MODEL_URL, headers=headers, json=payload)
|
| 24 |
+
response.raise_for_status() # Raise an HTTPError for bad responses (4xx, 5xx)
|
| 25 |
|
| 26 |
+
if response.status_code == 200:
|
| 27 |
+
result = response.json()
|
| 28 |
+
mix_design = result.get('mix_design', 'No design available.')
|
| 29 |
+
return format_mix_design(mix_design)
|
| 30 |
+
else:
|
| 31 |
+
return f"Error: Received status code {response.status_code}. Response: {response.text}"
|
| 32 |
+
except requests.exceptions.RequestException as e:
|
| 33 |
+
return f"Request failed: {e}"
|
| 34 |
|
| 35 |
+
# Function to format the mix design output
|
| 36 |
+
def format_mix_design(mix_design):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
if isinstance(mix_design, dict): # Check if we received valid data
|
| 38 |
+
return f"Recommended Concrete Mix Design (Using {mix_design.get('mix_code', 'Unknown')}):\n\n" \
|
| 39 |
f"- Cement: {mix_design.get('cement', 'N/A')} kg/m³\n" \
|
| 40 |
f"- Water: {mix_design.get('water', 'N/A')} liters/m³\n" \
|
| 41 |
f"- Fine Aggregate: {mix_design.get('fine_aggregate', 'N/A')} kg/m³\n" \
|
|
|
|
| 44 |
f"- Water-Cement Ratio: {mix_design.get('w_c_ratio', 'N/A')}\n" \
|
| 45 |
f"- Strength: {mix_design.get('strength', 'N/A')} MPa"
|
| 46 |
else:
|
| 47 |
+
return "No valid design returned."
|
| 48 |
+
|
| 49 |
+
# Function to handle the user interface logic
|
| 50 |
+
def concrete_mix_ui(strength, slump, w_c_ratio, coarse_aggregate, fine_aggregate, mix_code):
|
| 51 |
+
# Get the mix design based on the user's input and selected mix code
|
| 52 |
+
mix_design = get_concrete_mix_design(strength, slump, w_c_ratio, coarse_aggregate, fine_aggregate, mix_code)
|
| 53 |
+
return mix_design
|
| 54 |
|
| 55 |
# User Interface: Define the input components
|
| 56 |
inputs = [
|
|
|
|
| 76 |
theme="compact",
|
| 77 |
)
|
| 78 |
|
| 79 |
+
# Launch the app with public link
|
| 80 |
interface.launch(share=True)
|
| 81 |
+
|