Wallxtr/CS454_PROJECT
0
1"""2 3import gradio as gr4from tensorflow.keras.models import load_model5import numpy as np6from PIL import Image7 8# Load the model9try:10 model = load_model("custom_cnn_best_model (2).h5")11 print("Model loaded successfully.")12except Exception as e:13 print(f"Error loading model: {e}")14 15# Define the prediction function16def predict(image):17 try:18 image = image.resize((224, 224)) # Adjust size as per your model19 image_array = np.expand_dims(np.array(image) / 255.0, axis=0)20 predictions = model.predict(image_array)21 print(f"Prediction successful: {predictions}")22 return predictions.tolist()23 except Exception as e:24 print(f"Error during prediction: {e}")25 return "Error during prediction"26 27# Create the Gradio interface28try:29 interface = gr.Interface(30 fn=predict,31 inputs=gr.Image(type="pil"),32 outputs=gr.Label(),33 )34 print("Interface created successfully.")35except Exception as e:36 print(f"Error creating interface: {e}")37 38# Launch the interface39try:40 interface.launch()41 print("Interface launched successfully.")42except Exception as e:43 print(f"Error launching interface: {e}")44"""45 46import gradio as gr47 48def greet(name):49 return f"Hello, {name}!"50 51gr.Interface(fn=greet, inputs=gr.Textbox(), outputs="text").launch(debug=True)