Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,38 @@
|
|
1 |
-
import
|
|
|
2 |
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import pipeline
|
3 |
|
4 |
+
# Load the model from Hugging Face
|
5 |
+
model_name = "dejanseo/CTR-ZD"
|
6 |
+
model_pipeline = pipeline("text-classification", model=model_name)
|
7 |
+
|
8 |
+
# Mapping for the labels
|
9 |
+
labels_mapping = {
|
10 |
+
"LABEL_0": "Neutral impact",
|
11 |
+
"LABEL_1": "Positive impact",
|
12 |
+
"LABEL_2": "Negative impact"
|
13 |
+
}
|
14 |
+
|
15 |
+
def predict_title_impact(query, title):
|
16 |
+
# Concatenate query and title
|
17 |
+
input_text = f"{query} {title}"
|
18 |
+
predictions = model_pipeline(input_text)
|
19 |
+
return predictions
|
20 |
+
|
21 |
+
# Streamlit app
|
22 |
+
st.title("HTML Title CTR Prediction")
|
23 |
+
st.write("Predict the likelihood of a HTML title having an impact on CTR (click-through rate).")
|
24 |
+
|
25 |
+
# Input for the query and HTML title
|
26 |
+
query = st.text_input("Enter the Query:")
|
27 |
+
title = st.text_input("Enter the HTML Title:")
|
28 |
+
|
29 |
+
# Predict button
|
30 |
+
if st.button("Predict"):
|
31 |
+
if query and title:
|
32 |
+
predictions = predict_title_impact(query, title)
|
33 |
+
for prediction in predictions:
|
34 |
+
label = labels_mapping.get(prediction['label'], "Unknown")
|
35 |
+
st.write(f"Prediction: {label}")
|
36 |
+
st.write(f"Confidence: {prediction['score']:.2f}")
|
37 |
+
else:
|
38 |
+
st.write("Please enter both a query and an HTML title.")
|