Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files12345678910111213141516171819202122232425262728293031323334353637383940import altair as altimport numpy as npimport pandas as pdimport streamlit as st"""# Welcome to Streamlit!Edit `/streamlit_app.py` to customize this app to your heart's desire :heart:.If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [communityforums](https://discuss.streamlit.io).In the meantime, below is an example of what you can do with just a few lines of code:"""num_points = st.slider("Number of points in spiral", 1, 10000, 1100)num_turns = st.slider("Number of turns in spiral", 1, 300, 31)indices = np.linspace(0, 1, num_points)theta = 2 * np.pi * num_turns * indicesradius = indicesx = radius * np.cos(theta)y = radius * np.sin(theta)df = pd.DataFrame({"x": x,"y": y,"idx": indices,"rand": np.random.randn(num_points),})st.altair_chart(alt.Chart(df, height=700, width=700).mark_point(filled=True).encode(x=alt.X("x", axis=None),y=alt.Y("y", axis=None),color=alt.Color("idx", legend=None, scale=alt.Scale()),size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),))123456789101112131415161718192021222324252627282930313233343536373839404142434445import streamlit as stfrom transformers import AutoTokenizer, AutoModelForSeq2SeqLMimport re# ----------------------------# Загрузка модели# ----------------------------model_name = "Waris01/google-t5-finetuning-text-summarization"tokenizer = AutoTokenizer.from_pretrained(model_name)model = AutoModelForSeq2SeqLM.from_pretrained(model_name)# ----------------------------# Очистка текста# ----------------------------def clean_text(text):text = re.sub(r'\s+', ' ', text)text = re.sub(r'\[[0-9]+\]', '', text)text = re.sub(r'http\S+', '', text)return text.strip()# ----------------------------# Генерация суммаризации# ----------------------------def summarize(text):cleaned = clean_text(text)inputs = tokenizer("summarize: " + cleaned, return_tensors="pt", truncation=True, max_length=512)summary_ids = model.generate(inputs["input_ids"], max_length=150, num_beams=2, early_stopping=True)return tokenizer.decode(summary_ids[0], skip_special_tokens=True)# ----------------------------# Интерфейс Streamlit# ----------------------------st.title("🧬 Scientific Article Summarizer")st.write("Вставьте текст статьи и получите краткую аннотацию.")input_text = st.text_area("Введите текст статьи:", height=250)if st.button("Суммаризировать"):if len(input_text.strip()) == 0:st.error("Введите текст!")else:with st.spinner("Генерация суммаризации..."):summary = summarize(input_text)st.subheader("📘 Краткое содержание:")st.write(summary)
src/streamlit_app.py+44-39