jcarbonnell commited on
Commit
bd9a64a
1 Parent(s): 2cb8678

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -0
app.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import torch
3
+ from transformers import pipeline
4
+ from summarizer import Summarizer
5
+
6
+ pipeline = pipeline(task='text-generation', model="DemocracyStudio/generate_nft_content")
7
+ summarize=Summarizer()
8
+
9
+ def main():
10
+ st.title("Text generation for the marketing content of NFTs")
11
+ st.subheader("Course project 'NLP with transformers' at opencampus.sh, Spring 2022")
12
+
13
+ st.sidebar.image("bayc crown.png", use_column_width=True)
14
+ topics=["NFT", "Blockchain", "Metaverse"]
15
+ choice = st.sidebar.selectbox("Select one topic", topics)
16
+
17
+ if choice == 'NFT':
18
+ keywords=st.text_area("Input 4 keywords here: (optional)")
19
+ length=st.text_area("How long should be your text? (default: 512 words)")
20
+
21
+ if st.button("Generate"):
22
+ prompt = "<|startoftext|>"
23
+ generated = torch.tensor(tokenizer.encode(prompt)).unsqueeze(0)
24
+ generated = generated.to(device)
25
+ sample_outputs = model.generate(
26
+ generated,
27
+ do_sample=True,
28
+ top_k=50,
29
+ max_length = 512,
30
+ top_p=0.95,
31
+ num_return_sequences=1
32
+ )
33
+ for i, sample_output in enumerate(sample_outputs):
34
+ generated_text = tokenizer.decode(sample_output,
35
+ skip_special_tokens=True)
36
+
37
+ st.text("Keywords: {}\n".format(keywords))
38
+ st.text("Length in number of words: {}\n".format(length))
39
+ st.text("This is your tailored blog article {generated_text}")
40
+ summary = summarize(generated_text, num_sentences=1)
41
+ st.text("This is a tweet-sized summary of your article {summary}")
42
+
43
+ else:
44
+ st.write("Topic not available yet")
45
+