prakashkota commited on
Commit
5ce3bff
·
verified ·
1 Parent(s): e5910e5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -57
app.py CHANGED
@@ -1,65 +1,26 @@
1
- #+--------------------------------------------------------------------------------------------+
2
- # Breast Cancer Prediction
3
- # Using Neural Networks and Tensorflow
4
- # Prediction using Gradio on Hugging Face
5
- # Written by: Prakash R. Kota
6
- # Written on: 12 Feb 2025
7
- # Last update: 12 Feb 2025
8
 
9
- # Data Set from
10
- # Original:
11
- # https://archive.ics.uci.edu/dataset/17/breast+cancer+wisconsin+diagnostic
12
- # With Header:
13
- # https://www.kaggle.com/code/nancyalaswad90/analysis-breast-cancer-prediction-dataset
14
- #
15
- # Input Data Format for Gradio must be in the above header format with 30 features
16
- # The header has 32 features listed, but ignore the first 2 header columns
17
- #+--------------------------------------------------------------------------------------------+
18
 
19
- import tensorflow as tf
20
- import numpy as np
21
- import gradio as gr
22
- import joblib
23
-
24
-
25
- # Load the trained model
26
- model = tf.keras.models.load_model("PRK_BC_NN_Model.keras")
27
-
28
- # Load the saved Scaler
29
- scaler = joblib.load("PRK_BC_NN_Scaler.pkl")
30
-
31
- # Function to process input and make predictions
32
- def predict(input_text):
33
- # Convert input string into a NumPy array of shape (1, 30)
34
- input_data = np.array([list(map(float, input_text.split(",")))])
35
 
36
- # Ensure the input shape is correct
37
- if input_data.shape != (1, 30):
38
- return "Error: Please enter exactly 30 numerical values separated by commas."
39
-
40
- # Transform the input data using the loded scaler
41
- input_data_scaled = scaler.transform(input_data)
42
-
43
- # Make a prediction
44
- prediction = model.predict(input_data_scaled)
45
-
46
- # Convert prediction to a binary outcome (assuming classification)
47
- result = "Malignant" if prediction[0][0] > 0.5 else "Benign"
48
 
49
- return f"Prediction: {result} (Confidence: {prediction[0][0]:.2f})"
50
-
51
 
52
- import gradio as gr
 
 
53
 
54
- # Create the Gradio interface
55
- interface = gr.Interface(
56
- fn=predict,
57
- inputs=gr.Textbox(label="Enter 30 feature values, comma-separated"),
58
- outputs="text",
59
- title="Breast Cancer Prediction",
60
- description="Enter 30 numerical feature values separated by commas to predict whether the biopsy is Malignant or Benign."
61
- )
62
 
63
- # Launch the Gradio app
64
- interface.launch()
65
 
 
1
+ # Written On: 10 Feb 2025
2
+ # Last Updaate: 10 Feb 2025
 
 
 
 
 
3
 
4
+ #from transformers.utils import logging
5
+ #logging.set_verbosity_error()
 
 
 
 
 
 
 
6
 
7
+ #import warnings
8
+ #warnings.filterwarnings("ignore",
9
+ # message="Using the model-agnostic default `max_length`")
 
 
 
 
 
 
 
 
 
 
 
 
 
10
 
11
+ import gradio as gr
12
+ from transformers import pipeline
 
 
 
 
 
 
 
 
 
 
13
 
14
+ pipe = pipeline("image-to-text",
15
+ model="./models/Salesforce/blip-image-captioning-base")
16
 
17
+ def launch(input):
18
+ out = pipe(input)
19
+ return out[0]['generated_text']
20
 
21
+ iface = gr.Interface(launch,
22
+ inputs=gr.Image(type='pil'),
23
+ outputs="text")
 
 
 
 
 
24
 
25
+ iface.launch()
 
26