File size: 3,143 Bytes
fb96795
 
 
 
 
 
 
4baf6f4
 
 
fb96795
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import streamlit as st
# import openai
import replicate
import os
from dotenv import load_dotenv
from streamlit_extras.stylable_container import stylable_container
import streamlit_extras
load_dotenv()
REPLICATE_API_TOKEN = os.environ.get("REPLICATE_API_TOKEN")
replicate = replicate.Client(api_token=REPLICATE_API_TOKEN)

streamlit_style = """
            <style>
            #MainMenu {visibility: hidden;}
            footer {visibility: hidden;}
            video{width:200px;}
            .css-1wbqy5l {visibility: hidden;}
            .css-15zrgzn {visibility: hidden;}
            .css-klqnuk {visibility: hidden;}
            .en6cib64 {visibility: hidden;}
            .css-1u4fkce {visibility: hidden;}
            .en6cib62 {visibility: hidden;}
            .css-19rxjzo, .ef3psqc11 {
            background-color: purple;
            text-color: white;
            }
            div.stButton > button:first-child {
            background-color: darkgreen;
            text-weight: bold;
            }
            
            </style>
            """
def page6():
    with stylable_container(
         key="title",
         css_styles=[
             """ span {
                text-align: center;
                padding-top: 0px;
                padding-right: 0px;
                padding-bottom: 0px;
                padding-left: 0px;
                }"""
                ,
                """
                st-emotion-cache-0{
                     text-align: center;
                padding-top: 0px;
                padding-right: 0px;
                padding-bottom: 0px;
                padding-left: 0px;
                }""",
                
                """
                .e1f1d6gn0{
                     text-align: center;
                padding-top: 0px;
                padding-right: 0px;
                padding-bottom: 0px;
                padding-left: 0px;
                }
                
               
        """,
        ],
        
    ):
        st.markdown("<h3>Image to Text</h3>", unsafe_allow_html=True) #This is under a css style 
    st.markdown(streamlit_style, unsafe_allow_html=True) 
    
    
    image_file=st.file_uploader("Select Image", type=['jpeg','jpg','png'])
    
    if image_file is not None:
        placeholder=st.empty()
        col1,col2=placeholder.columns(2)
        col1.text("Uploaded Image")
        col1.image(image_file)
        prompt = st.text_input(label='Ask question related to image')          

    
    submit_button = st.button(label='Requestion Answer')
    
    
    
    if submit_button:
        if prompt and (image_file is not None):
            with st.spinner("Recognizing Image...."):
                output = replicate.run(
                    "nateraw/video-llava:a494250c04691c458f57f2f8ef5785f25bc851e0c91fd349995081d4362322dd",                    input={
                        "image_path": image_file,
                        "text_prompt": prompt
                    }
                )
                print(output)
                
                col2.text("Response")
                col2.markdown(output)