-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a6d2a63
commit ef29c38
Showing
3 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import base64 | ||
|
||
import streamlit as st | ||
from PIL import Image | ||
|
||
from .base import BaseTemplate | ||
from .utils import display_text_prediction | ||
|
||
|
||
class Template(BaseTemplate): | ||
This comment has been minimized.
Sorry, something went wrong. |
||
title = ( | ||
'<span style="color:salmon;">Image</span> ' | ||
'<span style="color:slategray;">to</span> ' | ||
'<span style="color:lightseagreen;">Text</span>' | ||
) | ||
|
||
def render(self): | ||
super().render() | ||
with st.form("Image Upload", clear_on_submit=True): | ||
uploaded_file = st.file_uploader( | ||
"Choose an image...", type=["jpg", "png", "jpeg"] | ||
) | ||
st.form_submit_button("Upload and Run") | ||
|
||
col1, col2 = st.columns(2) | ||
col1.markdown( | ||
'<h3 style="text-align: center;">Input</h3>', | ||
unsafe_allow_html=True, | ||
) | ||
col2.markdown( | ||
'<h3 style="text-align: center;">Result</h3>', | ||
unsafe_allow_html=True, | ||
) | ||
if uploaded_file is not None: | ||
image = Image.open(uploaded_file) | ||
col1.image(image, use_column_width=True) | ||
base64_img_str = base64.b64encode(uploaded_file.getvalue()).decode() | ||
with st.spinner("Waiting for result"): | ||
prediction = self.auto_predict({"base64_img_str": base64_img_str}) | ||
display_text_prediction(prediction, component=col2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
最好新开一个pull request来做这个,这样commit会比较清晰,也可以快点把部分代码merge了。