aidan-o-brien
commited on
Commit
•
4948c4f
1
Parent(s):
99fb15f
Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from distutils.command.upload import upload
|
2 |
+
from io import StringIO
|
3 |
+
import pandas as pd
|
4 |
+
import streamlit as st
|
5 |
+
|
6 |
+
from transformers import AutoTokenizer, TFAutoModelForQuestionAnswering
|
7 |
+
|
8 |
+
|
9 |
+
@st.cache
|
10 |
+
def load_data(file):
|
11 |
+
df = pd.read_csv(file, encoding='utf-8', nrows=50)
|
12 |
+
return df
|
13 |
+
|
14 |
+
|
15 |
+
@st.cache
|
16 |
+
def load_model_tokenizer():
|
17 |
+
tokenizer_cp = "albert-base-v2"
|
18 |
+
model_cp = "aidan-o-brien/recipe-improver"
|
19 |
+
tokenizer = AutoTokenizer.from_pretrained(tokenizer_cp)
|
20 |
+
model = TFAutoModelForQuestionAnswering.from_pretrained(model_cp)
|
21 |
+
return model, tokenizer
|
22 |
+
|
23 |
+
|
24 |
+
# Page config
|
25 |
+
title = "Recipe Improver"
|
26 |
+
icon = "🍣"
|
27 |
+
st.set_page_config(page_title=title, page_icon=icon)
|
28 |
+
st.title(title)
|
29 |
+
|
30 |
+
# Load csv
|
31 |
+
uploaded_file = st.file_uploader("Choose a csv file", type="csv", key='file_uploader')
|
32 |
+
if uploaded_file is not None:
|
33 |
+
df = load_data(uploaded_file)
|
34 |
+
st.write(df.head())
|
35 |
+
|
36 |
+
# Load tokenizer and model
|
37 |
+
model, tokenizer = load_model_tokenizer()
|
38 |
+
st.write("Model and tokenizer successfully loaded.")
|
39 |
+
|
40 |
+
# Pre-process data from csv file
|
41 |
+
|
42 |
+
|
43 |
+
# Run inference
|
44 |
+
|
45 |
+
|
46 |
+
# Post-process output of model
|
47 |
+
|
48 |
+
|
49 |
+
# Present results
|