feat: create app.py file
Browse files- src/app.py +98 -0
src/app.py
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from PIL import Image
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
st.title("📝 Visual Question Answering Project", )
|
| 8 |
+
|
| 9 |
+
width_head = """
|
| 10 |
+
<style>
|
| 11 |
+
[data-testid="stApp"] {
|
| 12 |
+
background: url(https://img.freepik.com/free-photo/vivid-blurred-colorful-background_58702-2655.jpg);
|
| 13 |
+
background-attachment: fixed;
|
| 14 |
+
background-repeat: no-repeat;
|
| 15 |
+
background-size: cover;
|
| 16 |
+
}
|
| 17 |
+
[data-testid="StyledLinkIconContainer" span] {
|
| 18 |
+
white-space : nowrap;
|
| 19 |
+
background: -webkit-linear-gradient(#eee, #333);
|
| 20 |
+
-webkit-background-clip: text;
|
| 21 |
+
# -webkit-text-fill-color: transparent;
|
| 22 |
+
}
|
| 23 |
+
.st-emotion-cache-zt5igj span {
|
| 24 |
+
white-space: nowrap;
|
| 25 |
+
background: linear-gradient(172deg, #c42525cf, #2130ae);
|
| 26 |
+
-webkit-background-clip: text;
|
| 27 |
+
background-clip: text;
|
| 28 |
+
-webkit-text-fill-color: transparent;
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
[data-testid="element-container"]{
|
| 32 |
+
text-align: -webkit-center;
|
| 33 |
+
|
| 34 |
+
}
|
| 35 |
+
[data-testid="baseButton-secondaryFormSubmit"]{
|
| 36 |
+
padding: 12px 40px;
|
| 37 |
+
}
|
| 38 |
+
</style>
|
| 39 |
+
"""
|
| 40 |
+
st.markdown(width_head, unsafe_allow_html=True)
|
| 41 |
+
# Custom CSS to create a border
|
| 42 |
+
border_css = """
|
| 43 |
+
<style>
|
| 44 |
+
.custom-border {
|
| 45 |
+
border: 10px solid #4CAF50; /* Green border */
|
| 46 |
+
padding: 10px;
|
| 47 |
+
border-radius: 5px;
|
| 48 |
+
}
|
| 49 |
+
</style>
|
| 50 |
+
"""
|
| 51 |
+
|
| 52 |
+
st.markdown('<div class="custom-border">', unsafe_allow_html=True)
|
| 53 |
+
# st.write("This is inside a bordered box")
|
| 54 |
+
st1, st2 = st.columns(2)
|
| 55 |
+
image = None
|
| 56 |
+
if image == None:
|
| 57 |
+
uploaded_file = st.file_uploader("Upload an article", type=("png", "jpg"))
|
| 58 |
+
# Check if a file has been uploaded
|
| 59 |
+
if uploaded_file is not None:
|
| 60 |
+
# Open the image using PIL
|
| 61 |
+
image = Image.open(uploaded_file)
|
| 62 |
+
|
| 63 |
+
quesiton: str = ""
|
| 64 |
+
if image != None:
|
| 65 |
+
with st.form("my_form"):
|
| 66 |
+
col1, col2 = st.columns(2)
|
| 67 |
+
with col1:
|
| 68 |
+
question = st.text_area("Enter text:", placeholder="What is your question?")
|
| 69 |
+
with col2:
|
| 70 |
+
st.image(image, caption="Uploaded Image.", use_column_width=True)
|
| 71 |
+
submitted = st.form_submit_button("Submit")
|
| 72 |
+
|
| 73 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
# if not openai_api_key:
|
| 77 |
+
# st.info("Please add your OpenAI API key to continue.")
|
| 78 |
+
# elif submitted:
|
| 79 |
+
# generate_response(text)
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
# if uploaded_file and question and not anthropic_api_key:
|
| 83 |
+
# st.info("Please add your Anthropic API key to continue.")
|
| 84 |
+
|
| 85 |
+
# if uploaded_file and question and anthropic_api_key:
|
| 86 |
+
# article = uploaded_file.read().decode()
|
| 87 |
+
# prompt = f"""{anthropic.HUMAN_PROMPT} Here's an article:\n\n
|
| 88 |
+
# {article}\n\n\n\n{question}{anthropic.AI_PROMPT}"""
|
| 89 |
+
|
| 90 |
+
# client = anthropic.Client(api_key=anthropic_api_key)
|
| 91 |
+
# response = client.completions.create(
|
| 92 |
+
# prompt=prompt,
|
| 93 |
+
# stop_sequences=[anthropic.HUMAN_PROMPT],
|
| 94 |
+
# model="claude-v1", #"claude-2" for Claude 2 model
|
| 95 |
+
# max_tokens_to_sample=100,
|
| 96 |
+
# )
|
| 97 |
+
# st.write("### Answer")
|
| 98 |
+
# st.write(response.completion)
|