Update app.py
Browse files
app.py
CHANGED
|
@@ -1,53 +1,36 @@
|
|
| 1 |
-
import
|
| 2 |
-
import
|
| 3 |
import numpy as np
|
| 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 |
-
# Draw white rectangle as background for text
|
| 38 |
-
cv2.rectangle(image_rgb, (x, y), (x + w, y + h), (255, 255, 255), -1)
|
| 39 |
-
|
| 40 |
-
# Adjust font scale based on box height
|
| 41 |
-
font_scale = h / 35
|
| 42 |
-
font_thickness = 1
|
| 43 |
-
|
| 44 |
-
# Overlay translated text, vertically aligned inside the box
|
| 45 |
-
cv2.putText(image_rgb, translated_text, (x, y + h - 5),
|
| 46 |
-
cv2.FONT_HERSHEY_SIMPLEX, font_scale, (0, 0, 0),
|
| 47 |
-
font_thickness, cv2.LINE_AA)
|
| 48 |
-
except Exception as e:
|
| 49 |
-
print(f"Translation error for '{text}': {e}")
|
| 50 |
-
|
| 51 |
-
# Convert back to RGB for PIL display
|
| 52 |
-
result_image = cv2.cvtColor(image_rgb, cv2.COLOR_BGR2RGB)
|
| 53 |
-
st.image(result_image, caption="Translated Image", use_column_width=True)
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import pandas as pd
|
| 3 |
import numpy as np
|
| 4 |
+
import pickle
|
| 5 |
+
|
| 6 |
+
def predict_diabetes(pregnancies, glucose, blood_pressure, skin_thickness, insulin, bmi, diabetes_pedigree_function, age):
|
| 7 |
+
# Load the model
|
| 8 |
+
with open("model.pkl", "rb") as f:
|
| 9 |
+
model = pickle.load(f)
|
| 10 |
+
|
| 11 |
+
input_data = np.array([[pregnancies, glucose, blood_pressure, skin_thickness, insulin, bmi, diabetes_pedigree_function, age]])
|
| 12 |
+
prediction = model.predict(input_data)
|
| 13 |
+
result = "Diabetic" if prediction[0] == 1 else "Not Diabetic"
|
| 14 |
+
return result
|
| 15 |
+
|
| 16 |
+
# Gradio Interface
|
| 17 |
+
description = "Diabetes Prediction Model - Enter your values below"
|
| 18 |
+
|
| 19 |
+
demo = gr.Interface(
|
| 20 |
+
fn=predict_diabetes,
|
| 21 |
+
inputs=[
|
| 22 |
+
gr.Number(label="Pregnancies"),
|
| 23 |
+
gr.Number(label="Glucose"),
|
| 24 |
+
gr.Number(label="Blood Pressure"),
|
| 25 |
+
gr.Number(label="Skin Thickness"),
|
| 26 |
+
gr.Number(label="Insulin"),
|
| 27 |
+
gr.Number(label="BMI"),
|
| 28 |
+
gr.Number(label="Diabetes Pedigree Function"),
|
| 29 |
+
gr.Number(label="Age")
|
| 30 |
+
],
|
| 31 |
+
outputs=gr.Text(label="Prediction"),
|
| 32 |
+
title="Diabetes Prediction",
|
| 33 |
+
description=description
|
| 34 |
+
)
|
| 35 |
+
|
| 36 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|