Spaces:
Runtime error
Runtime error
ADD: Initial version of app
Browse files
app.py
ADDED
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
3 |
+
import numpy as np
|
4 |
+
import torch
|
5 |
+
|
6 |
+
|
7 |
+
def main():
|
8 |
+
|
9 |
+
st.set_page_config(
|
10 |
+
layout="wide",
|
11 |
+
initial_sidebar_state="auto",
|
12 |
+
page_title="Title Generator!",
|
13 |
+
page_icon=None,
|
14 |
+
)
|
15 |
+
|
16 |
+
st.title("Title Generator: Generate a title from the abstract of a paper")
|
17 |
+
st.text("")
|
18 |
+
st.text("")
|
19 |
+
|
20 |
+
example_prompts = [
|
21 |
+
"""Neural Painters is a class of models that follows a GAN framework to generate brushstrokes, which are then composed to create paintings. GANs are great generative models for AI Art but they are known to be notoriously difficult to train. To overcome GAN's limitations and to speed up the Neural Painter training, we applied Transfer Learning to the process reducing it from days to only hours, while achieving the same level of visual aesthetics in the final paintings generated. We report our approach and results in this work.""",
|
22 |
+
"""In autonomous driving, learning a segmentation model that can adapt to various environmental conditions is crucial. In particular, copying with severe illumination changes is an impelling need, as models trained on daylight data will perform poorly at nighttime. In this paper, we study the problem of Domain Adaptive Nighttime Semantic Segmentation (DANSS), which aims to learn a discriminative nighttime model with a labeled daytime dataset and an unlabeled dataset, including coarsely aligned day-night image pairs. To this end, we propose a novel Bidirectional Mixing (Bi-Mix) framework for DANSS, which can contribute to both image translation and segmentation adaptation processes. Specifically, in the image translation stage, Bi-Mix leverages the knowledge of day-night image pairs to improve the quality of nighttime image relighting. On the other hand, in the segmentation adaptation stage, Bi-Mix effectively bridges the distribution gap between day and night domains for adapting the model to the night domain. In both processes, Bi-Mix simply operates by mixing two samples without extra hyper-parameters, thus it is easy to implement. Extensive experiments on Dark Zurich and Nighttime Driving datasets demonstrate the advantage of the proposed Bi-Mix and show that our approach obtains state-of-the-art performance in DANSS."""
|
23 |
+
]
|
24 |
+
|
25 |
+
example = st.selectbox("Choose an example abstract", example_prompts)
|
26 |
+
|
27 |
+
# Take the message which needs to be processed
|
28 |
+
message = st.text_area("...or paste a papers abstract to generate a title", example)
|
29 |
+
# st.title(message)
|
30 |
+
st.text("")
|
31 |
+
models_to_choose = [
|
32 |
+
"AryanLala/autonlp-Scientific_Title_Generator-34558227",
|
33 |
+
]
|
34 |
+
|
35 |
+
BASE_MODEL = st.selectbox("Choose a model to generate the title", models_to_choose)
|
36 |
+
|
37 |
+
def preprocess(text):
|
38 |
+
if BASE_MODEL == "AryanLala/autonlp-Scientific_Title_Generator-34558227":
|
39 |
+
return [text]
|
40 |
+
else:
|
41 |
+
st.error("Please select a model first")
|
42 |
+
|
43 |
+
@st.cache(allow_output_mutation=True, suppress_st_warning=True, show_spinner=True)
|
44 |
+
def load_model():
|
45 |
+
tokenizer = AutoTokenizer.from_pretrained(BASE_MODEL)
|
46 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(BASE_MODEL)
|
47 |
+
return model, tokenizer
|
48 |
+
|
49 |
+
def get_summary(text):
|
50 |
+
model, tokenizer = load_model()
|
51 |
+
preprocessed = preprocess(text)
|
52 |
+
inputs = tokenizer(
|
53 |
+
preprocessed, truncation=True, padding="longest", return_tensors="pt"
|
54 |
+
)
|
55 |
+
output = model.generate(
|
56 |
+
**inputs,
|
57 |
+
max_length=60,
|
58 |
+
num_beams=10,
|
59 |
+
num_return_sequences=1,
|
60 |
+
temperature=1.5,
|
61 |
+
)
|
62 |
+
target_text = tokenizer.batch_decode(output, skip_special_tokens=True)
|
63 |
+
return target_text[0]
|
64 |
+
|
65 |
+
# Define function to run when submit is clicked
|
66 |
+
def submit(message):
|
67 |
+
if len(message) > 0:
|
68 |
+
emoji = get_summary(message)
|
69 |
+
html_str = f"""
|
70 |
+
<style>
|
71 |
+
p.a {{
|
72 |
+
font: 20px Courier;
|
73 |
+
}}
|
74 |
+
</style>
|
75 |
+
<p class="a">{emoji}</p>
|
76 |
+
"""
|
77 |
+
|
78 |
+
st.markdown(html_str, unsafe_allow_html=True)
|
79 |
+
# st.markdown(emoji)
|
80 |
+
else:
|
81 |
+
st.error("The text can't be empty")
|
82 |
+
|
83 |
+
# Run algo when submit button is clicked
|
84 |
+
if st.button("Submit"):
|
85 |
+
submit(message)
|
86 |
+
|
87 |
+
|
88 |
+
|
89 |
+
if __name__ == "__main__":
|
90 |
+
main()
|