pavuluriashwitha commited on
Commit
9f6b670
·
verified ·
1 Parent(s): d8f9f27

Update Home.py

Browse files
Files changed (1) hide show
  1. Home.py +50 -15
Home.py CHANGED
@@ -1,22 +1,57 @@
 
 
 
 
1
  import streamlit as st
2
- from transformers import pipeline
 
 
 
3
 
4
- # Load the text generation pipeline
5
- @st.cache_resource
6
- def load_model():
7
- return pipeline("text-generation", model="tiiuae/falcon-7b-instruct")
8
 
9
- model = load_model()
 
 
 
 
 
10
 
11
- # Streamlit UI
12
- st.title("Convolution_Neural_Network")
 
 
 
 
 
 
 
13
 
14
- # User input
15
- user_input = st.text_area("Enter a prompt:", "Once upon a time...")
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
- if st.button("Generate"):
18
- with st.spinner("Generating text..."):
19
- output = model(user_input, max_length=100, num_return_sequences=1)
20
- st.success("Generated Text:")
21
- st.write(output[0]['generated_text'])
22
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ os.system("pip install tensorflow")
3
+ os.system("pip install scikit-learn")
4
+
5
  import streamlit as st
6
+ import tensorflow as tf
7
+ import numpy as np
8
+ import pickle
9
+ from PIL import Image
10
 
11
+ # Constants
12
+ MODEL_PATH = "image_classification.h5"
13
+ LABEL_ENCODER_PATH = "le.pkl"
14
+ EXPECTED_SIZE = (64, 64) # Update this based on your model's input shape
15
 
16
+ def load_resources():
17
+ """Load model and label encoder."""
18
+ model = tf.keras.models.load_model(MODEL_PATH)
19
+ with open(LABEL_ENCODER_PATH, "rb") as f:
20
+ label_encoder = pickle.load(f)
21
+ return model, label_encoder
22
 
23
+ # Load resources
24
+ model, label_encoder = load_resources()
25
+
26
+ def preprocess_image(image):
27
+ """Resize image to match model input shape."""
28
+ image = image.resize(EXPECTED_SIZE) # Resize to match model input
29
+ image_array = np.array(image) # Convert to numpy array
30
+ image_array = np.expand_dims(image_array, axis=0) # Add batch dimension
31
+ return image_array
32
 
33
+ def predict(image):
34
+ """Predict the class of the uploaded image."""
35
+ image_array = preprocess_image(image)
36
+ preds = model.predict(image_array)
37
+ class_index = np.argmax(preds)
38
+ return label_encoder.inverse_transform([class_index])[0]
39
+
40
+ # Streamlit UI
41
+ st.set_page_config(page_title="Image Classifier", layout="wide")
42
+ st.markdown("""
43
+ <h1 style='text-align: center; color: #4A90E2;'>🖼️ Image Classification App</h1>
44
+ <p style='text-align: center; font-size: 18px;'>Upload an image and let our model classify it for you!</p>
45
+ <hr>
46
+ """, unsafe_allow_html=True)
47
 
48
+ st.sidebar.header("Upload Your Image")
49
+ uploaded_file = st.sidebar.file_uploader("Choose an image", type=["jpg", "png", "jpeg"], help="Supported formats: JPG, PNG, JPEG")
 
 
 
50
 
51
+ if uploaded_file:
52
+ image = Image.open(uploaded_file)
53
+ st.image(image, caption="📸 Uploaded Image", use_column_width=True)
54
+
55
+ if st.button("🔍 Classify Image", use_container_width=True):
56
+ prediction = predict(image)
57
+ st.success(f"🎯 Predicted Class: {prediction}")