application file added
Browse files- app.py +36 -0
- model_9.h5 +3 -0
- requirements.txt +4 -0
app.py
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import tensorflow as tf
|
2 |
+
import numpy as np
|
3 |
+
from PIL import Image
|
4 |
+
import gradio as gr
|
5 |
+
|
6 |
+
# CNN+LSTM model loaded
|
7 |
+
model = tf.keras.models.load_model("model_9.h5")
|
8 |
+
|
9 |
+
# Define the preprocessing function for the image
|
10 |
+
def preprocess_image(image):
|
11 |
+
# Resize and normalize image to match model's expected input shape
|
12 |
+
image = image.resize((224, 224)) # Modify size based on your model
|
13 |
+
image_array = np.array(image) / 255.0 # Normalize
|
14 |
+
image_array = np.expand_dims(image_array, axis=0) # Add batch dimension
|
15 |
+
return image_array
|
16 |
+
|
17 |
+
# Define the function that generates a caption from the image
|
18 |
+
def generate_caption(image):
|
19 |
+
preprocessed_image = preprocess_image(image)
|
20 |
+
|
21 |
+
# Generate a caption from the model
|
22 |
+
# Note: Adjust this if your model requires a sequence start token or has a decoding loop
|
23 |
+
caption_tokens = model.predict(preprocessed_image)
|
24 |
+
|
25 |
+
return caption_tokens
|
26 |
+
|
27 |
+
# Define the Gradio interface
|
28 |
+
iface = gr.Interface(
|
29 |
+
fn=generate_caption, # The function that generates captions
|
30 |
+
inputs=gr.inputs.Image(type="pil"), # Accept an image input
|
31 |
+
outputs="text", # Output a text caption
|
32 |
+
title="Image Captioning Model",
|
33 |
+
description="Upload an image, and the model will generate a caption describing it."
|
34 |
+
)
|
35 |
+
|
36 |
+
iface.launch()
|
model_9.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:9f851e1217ac2ccfe1166ff5848da48905b98c1883076d63a6b5d00871d4c49e
|
3 |
+
size 16970992
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
tensorflow
|
2 |
+
gradio
|
3 |
+
pillow
|
4 |
+
torch
|