tweet-ab / app.py
Jasper Gilley
updated return method and copy
2aeb7d3
raw
history blame contribute delete
954 Bytes
import gradio as gr
import autokeras as ak
import numpy as np
from tensorflow.keras.models import load_model
loaded_model = load_model("text_model", custom_objects=ak.CUSTOM_OBJECTS)
def tweet_tester(tweet1, tweet2):
pred1 = loaded_model.predict(np.array([[tweet1]]))[0][0]
pred2 = loaded_model.predict(np.array([[tweet2]]))[0][0]
print(pred1, pred2)
diff_pct = (pred1 - pred2) / pred1 * 100
# truncate diff_pct to 2 decimal places
diff_pct = round(diff_pct, 3)
if diff_pct > 0:
return f"tweet2 is {diff_pct}% better than tweet1"
else:
return f"tweet2 is {abs(diff_pct)}% worse than tweet1"
interface = gr.Interface(
title="Tweet A/B Test",
description="Enter the text of two tweets you'd like to A/B test. The output number represents the percent difference in expected likes between the two tweets.",
fn=tweet_tester,
inputs=["text", "text"],
outputs=["text"]
)
interface.launch()