File size: 954 Bytes
b07085b
 
 
 
 
 
 
 
 
 
 
 
 
 
2aeb7d3
 
 
 
b07085b
 
 
2aeb7d3
b07085b
 
2aeb7d3
b07085b
2aeb7d3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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()