File size: 1,639 Bytes
2a02e90
bc0caee
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
40
41
42
43
import streamlit as st
import torch
import pandas as pd
from utils import load_model_and_tokenizer, preprocess_input, predict_property
from attention_plot import plot_attention_heatmap

st.set_page_config(page_title="TransPolymer Predictor", layout="centered")
st.title("πŸ”¬ TransPolymer Property Prediction")
st.markdown("Masukkan struktur polimer (SMILES) dan maklumat deskriptor.")

tokenizer, model = load_model_and_tokenizer()

# Input form
with st.form("polymer_form"):
    smiles = st.text_input("πŸ“„ Polymer SMILES", value="*CCO*")
    temp = st.number_input("🌑️ Suhu (°C)", value=25.0)
    mw = st.number_input("βš–οΈ Berat Molekul (kDa)", value=100.0)
    submitted = st.form_submit_button("Jalankan Ramalan")

if submitted:
    input_seq = preprocess_input(smiles, temp, mw)
    pred = predict_property(input_seq, model, tokenizer)
    st.success(f"πŸ“Š Ramalan Sifat Polimer: **{pred:.4f}**")
    st.markdown("### 🎯 Visualisasi Attention (Last Layer)")
    fig = plot_attention_heatmap(model, tokenizer, input_seq)
    st.pyplot(fig)

# Batch prediction
st.markdown("---")
st.header("πŸ“ Batch Prediction (CSV)")
uploaded_file = st.file_uploader("Muat naik CSV dengan lajur: `smiles`, `temp`, `mw`", type="csv")

if uploaded_file:
    df = pd.read_csv(uploaded_file)
    results = []
    for i, row in df.iterrows():
        seq = preprocess_input(row["smiles"], row["temp"], row["mw"])
        pred = predict_property(seq, model, tokenizer)
        results.append(pred)
    df["prediction"] = results
    st.dataframe(df)
    st.download_button("πŸ“₯ Muat turun hasil", df.to_csv(index=False), "predictions.csv")