Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,20 +1,17 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
HF_MODEL_URL = "https://api-inference.huggingface.co/models/
|
| 6 |
-
HF_API_KEY = "YOUR_HUGGINGFACE_API_KEY"
|
| 7 |
|
| 8 |
-
# Function to get
|
| 9 |
def get_concrete_mix_design(strength, slump, w_c_ratio, coarse_aggregate, fine_aggregate, mix_code):
|
| 10 |
payload = {
|
| 11 |
"inputs": {
|
| 12 |
-
"
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
"coarse_aggregate": coarse_aggregate,
|
| 16 |
-
"fine_aggregate": fine_aggregate,
|
| 17 |
-
"mix_code": mix_code
|
| 18 |
}
|
| 19 |
}
|
| 20 |
|
|
@@ -25,27 +22,13 @@ def get_concrete_mix_design(strength, slump, w_c_ratio, coarse_aggregate, fine_a
|
|
| 25 |
|
| 26 |
if response.status_code == 200:
|
| 27 |
result = response.json()
|
| 28 |
-
|
| 29 |
-
return
|
| 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" \
|
| 42 |
-
f"- Coarse Aggregate: {mix_design.get('coarse_aggregate', 'N/A')} kg/m³\n" \
|
| 43 |
-
f"- Admixture: {mix_design.get('admixture', 'N/A')} liters/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
|
|
@@ -79,3 +62,4 @@ interface = gr.Interface(
|
|
| 79 |
# Launch the app with public link
|
| 80 |
interface.launch(share=True)
|
| 81 |
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
| 3 |
|
| 4 |
+
# Using a general-purpose model hosted on Hugging Face
|
| 5 |
+
HF_MODEL_URL = "https://api-inference.huggingface.co/models/distilbert-base-uncased"
|
| 6 |
+
HF_API_KEY = "YOUR_HUGGINGFACE_API_KEY" # Make sure your API key is valid
|
| 7 |
|
| 8 |
+
# Function to get a response 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 |
+
"text": f"Strength: {strength} MPa, Slump: {slump} mm, Water-Cement Ratio: {w_c_ratio}, "
|
| 13 |
+
f"Coarse Aggregate: {coarse_aggregate} kg/m³, Fine Aggregate: {fine_aggregate} kg/m³, "
|
| 14 |
+
f"Mix Code: {mix_code}"
|
|
|
|
|
|
|
|
|
|
| 15 |
}
|
| 16 |
}
|
| 17 |
|
|
|
|
| 22 |
|
| 23 |
if response.status_code == 200:
|
| 24 |
result = response.json()
|
| 25 |
+
generated_text = result.get('generated_text', 'No response from model.')
|
| 26 |
+
return generated_text
|
| 27 |
else:
|
| 28 |
return f"Error: Received status code {response.status_code}. Response: {response.text}"
|
| 29 |
except requests.exceptions.RequestException as e:
|
| 30 |
return f"Request failed: {e}"
|
| 31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
# Function to handle the user interface logic
|
| 33 |
def concrete_mix_ui(strength, slump, w_c_ratio, coarse_aggregate, fine_aggregate, mix_code):
|
| 34 |
# Get the mix design based on the user's input and selected mix code
|
|
|
|
| 62 |
# Launch the app with public link
|
| 63 |
interface.launch(share=True)
|
| 64 |
|
| 65 |
+
|