|
|
import streamlit as st |
|
|
import pandas as pd |
|
|
import matplotlib.pyplot as plt |
|
|
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM |
|
|
|
|
|
|
|
|
@st.cache_resource |
|
|
def load_model(): |
|
|
tokenizer = AutoTokenizer.from_pretrained("t5-small") |
|
|
model = AutoModelForSeq2SeqLM.from_pretrained("t5-small") |
|
|
return tokenizer, model |
|
|
|
|
|
tokenizer, model = load_model() |
|
|
|
|
|
|
|
|
st.title("Seismic Event Prediction App") |
|
|
|
|
|
|
|
|
uploaded_file = st.file_uploader("Upload CSV File", type=["csv"]) |
|
|
|
|
|
if uploaded_file is not None: |
|
|
|
|
|
data = pd.read_csv(uploaded_file) |
|
|
|
|
|
|
|
|
st.write("## Uploaded Data") |
|
|
st.dataframe(data) |
|
|
|
|
|
|
|
|
st.write("## Select an example to visualize:") |
|
|
idx = st.slider("Choose an index", 0, len(data) - 1, 0) |
|
|
|
|
|
|
|
|
st.write("### Selected example:", idx) |
|
|
st.write(data.iloc[idx]) |
|
|
|
|
|
|
|
|
fig, ax = plt.subplots() |
|
|
ax.plot(data['x'], label="X-axis data", color="blue") |
|
|
ax.axvline(x=data.iloc[idx]['prediction'], color="red", label="Predicted Earthquake") |
|
|
ax.legend() |
|
|
st.pyplot(fig) |
|
|
|
|
|
|
|
|
input_text = f"Predict seismic event for index {idx}." |
|
|
inputs = tokenizer.encode(input_text, return_tensors="pt") |
|
|
outputs = model.generate(inputs, max_length=50, num_beams=4, early_stopping=True) |
|
|
generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True) |
|
|
|
|
|
st.write("### Model Prediction:") |
|
|
st.write(generated_text) |
|
|
|