ahmadrocks commited on
Commit
80b6635
1 Parent(s): 679da8a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -6
app.py CHANGED
@@ -1,9 +1,23 @@
1
  import streamlit as st
2
- from transformers import pipeline
3
 
4
- pipe = pipeline("sentiment-analysis")
5
- text = st.text_area("Enter Text!")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
- if text:
8
- out = pipe(text)
9
- st.json(out)
 
1
  import streamlit as st
2
+ from transformers import GPT2LMHeadModel, GPT2Tokenizer
3
 
4
+ # Load the GPT-2 model and tokenizer
5
+ model_name = 'gpt2-large'
6
+ model = GPT2LMHeadModel.from_pretrained(model_name)
7
+ tokenizer = GPT2Tokenizer.from_pretrained(model_name)
8
+
9
+ st.title("Article Generator")
10
+
11
+ # Input for the article title
12
+ title = st.text_input("Enter the title of the article")
13
+
14
+ # Generate the article
15
+ if st.button("Generate Article"):
16
+ if title:
17
+ input_ids = tokenizer.encode(title, return_tensors='pt')
18
+ output = model.generate(input_ids, max_length=500, num_return_sequences=1, no_repeat_ngram_size=2, early_stopping=True)
19
+ article = tokenizer.decode(output[0], skip_special_tokens=True)
20
+ st.write(article)
21
+ else:
22
+ st.warning("Please enter a title to generate an article")
23