File size: 1,213 Bytes
c679076
 
02c6d49
c679076
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
29
30
31
32
33
34
35
36
37
38
39
import streamlit as st
from transformers import pipeline

# Load the model from Hugging Face
model_name = "dejanseo/CTR-ZD"
model_pipeline = pipeline("text-classification", model=model_name)

# Mapping for the labels
labels_mapping = {
    "LABEL_0": "Neutral impact",
    "LABEL_1": "Positive impact",
    "LABEL_2": "Negative impact"
}

def predict_title_impact(query, title):
    # Concatenate query and title
    input_text = f"{query} {title}"
    predictions = model_pipeline(input_text)
    return predictions

# Streamlit app
st.title("HTML Title CTR Prediction")
st.write("Predict the likelihood of a HTML title having an impact on CTR (click-through rate).")

# Input for the query and HTML title
query = st.text_input("Enter the Query:")
title = st.text_input("Enter the HTML Title:")

# Predict button
if st.button("Predict"):
    if query and title:
        predictions = predict_title_impact(query, title)
        for prediction in predictions:
            label = labels_mapping.get(prediction['label'], "Unknown")
            st.write(f"Prediction: {label}")
            st.write(f"Confidence: {prediction['score']:.2f}")
    else:
        st.write("Please enter both a query and an HTML title.")