RadiXGPT / app.py
Singularity666's picture
Update_app.py
13c4a71
import os
import pandas as pd
import numpy as np
from PIL import Image
import streamlit as st
import requests
import io
# Designing the interface
st.title("RadiXGPT")
with st.spinner('Loading objects ...'):
from model import *
random_image_id = get_random_image_id()
sample_name = f"ROCO_{str(random_image_id).zfill(5)}.jpg"
sample_path = os.path.join(sample_dir, sample_name)
image = Image.open(sample_path)
width, height = 299, 299
resized = image.resize(size=(width, height))
st.markdown(f"ROCO_{str(random_image_id).zfill(5)}.jpg")
show = st.image(resized)
show.image(resized, '\n\nSelected Image')
# For newline
st.sidebar.write('\n')
with st.spinner('Generating image caption ...'):
st.header(f'Predicted caption:\n\n')
preprocessed_img = preprocess_image_inception(resized)
features = extract_features(inception, preprocessed_img)
# Load the transformer model
transformer, _, _ = fetch_model('Transformer')
# Fetch the auxiliary files
word2Index, index2Word, variable_params = fetch_auxiliary_files('Transformer')
max_len = variable_params['max_caption_len']
# Generate the caption
caption = generate_caption(transformer, features, max_len, word2Index, index2Word)
st.subheader(caption)
st.sidebar.header("Model predicts: ")
st.sidebar.write(f"{caption}")
image.close()