File size: 1,346 Bytes
13c4a71
 
 
 
51c45e2
 
 
 
 
 
13c4a71
51c45e2
 
 
 
 
 
 
13c4a71
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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()