Download tensor_model/app.py from sauravx2/Ai: direct link, hf CLI and curl.
- Browser
- Download file 1.13 kB
-
https://huggingface.co/spaces/sauravx2/Ai/resolve/main/tensor_model/app.py
- Command line
-
hf download hf://spaces/sauravx2/Ai/tensor_model/app.py
-
curl -L -o app.py https://huggingface.co/spaces/sauravx2/Ai/resolve/main/tensor_model/app.py
1.13 kB
| import streamlit as st | |
| import tensorflow as tf | |
| from tensorflow.keras.preprocessing.image import load_img, img_to_array | |
| import numpy as np | |
| # Load the saved model | |
| model = tf.keras.models.load_model('model_cnn.h5') | |
| # Set up Streamlit app | |
| st.title("Real or Fake Image Classification") | |
| st.write("This app classifies images as real or fake using a CNN model.") | |
| # Upload an image | |
| uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "png", "jpeg"]) | |
| if uploaded_file is not None: | |
| # Display the uploaded image | |
| image = load_img(uploaded_file, target_size=(256, 256)) | |
| st.image(image, caption='Uploaded Image', use_column_width=True) | |
| st.write("") | |
| st.write("Classifying...") | |
| # Preprocess the image | |
| image = img_to_array(image) | |
| image = np.expand_dims(image, axis=0) | |
| image = tf.keras.applications.vgg16.preprocess_input(image) | |
| # Make predictions | |
| prediction = model.predict(image) | |
| predicted_label = 'Fake' if prediction[0] > 0.5 else 'Real' | |
| confidence = prediction[0] if predicted_label == 'Fake' else 1 - prediction[0] | |
| st.write(f"Prediction: {predicted_label} ") | |