Skip to content

Instantly share code, notes, and snippets.

@hamletbatista
Created December 10, 2020 02:27
Show Gist options
  • Save hamletbatista/e7714bd59357a83b36b1174ecf00bb03 to your computer and use it in GitHub Desktop.
Save hamletbatista/e7714bd59357a83b36b1174ecf00bb03 to your computer and use it in GitHub Desktop.
import streamlit as st
from ludwig.api import LudwigModel
import pandas as pd
st.cache(show_spinner=False)
def load_model():
#Update with the path to the Ludwig trained model
model = LudwigModel.load("results/experiment_run_1/model/")
return model
model = load_model()
st.header("Automated Title Tag Optimization Using Deep Learning\nby @hamletbatista")
st.text("This demo uses a Google T5 model trained for Title Tag Optimization")
add_text_sidebar = st.sidebar.title("Menu")
add_text_sidebar = st.sidebar.text("🐍🔥 DISCLAIMER\n You DON'T need to learn Python\n to be a great SEO.")
filename = st.text_input(label="Provide CSV filename with titles and keywords to optimize")
import pandas as pd
if len(filename) > 0 and filename.find(".csv") > 0:
test_df = pd.read_csv(filename)#("test.csv")
predictions = model.predict(test_df)
test_df = test_df.rename(columns={"Simplified_Title": "Original_Title"})
#st.text('Original Titles and Keywords:')
#st.write(test_df)
#st.table(test_df)
st.text('Optimized Titles:')
pred_df = predictions[0]
#Clean up titles
pred_df["Title"] = pred_df["Title_predictions"].apply(lambda x: " ".join(x))
final_df = test_df.join(pred_df)[["Original_Title", "Keyword", "Title"]].rename(columns={"Title": "Optimized_Title"})
#st.write(final_df)
st.table(final_df)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment