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) return diff_pct 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. If the number is positive, the second tweet is more likely to get more likes than the first tweet. If the number is negative, the first tweet is more likely to get more likes than the second tweet.", fn=tweet_tester, inputs=["text", "text"], outputs=["number"] ) interface.launch()