MaawaKhalid commited on
Commit
6a25254
·
verified ·
1 Parent(s): 5242bdf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -6
app.py CHANGED
@@ -1,9 +1,20 @@
1
  import streamlit as st
2
- from transformers import pipeline
3
 
4
- pipe = pipeline('sentiment-analysis')
5
- text = st.text_area('Enter some text:')
 
 
6
 
7
- if text:
8
- out = pipe(text)
9
- st.json(out)
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ from transformers import AutoTokenizer, AutoModelForCausalLM
3
 
4
+ # Define model and tokenizer
5
+ model_name = 'openai-community/gpt2-large'
6
+ model = AutoModelForCausalLM.from_pretrained(model_name)
7
+ tokenizer = AutoTokenizer.from_pretrained(model_name, use_fast=True)
8
 
9
+ def generate_blogpost(topic):
10
+ inputs = tokenizer.encode(topic, return_tensors='pt')
11
+ outputs = model.generate(inputs, max_length=500, num_return_sequences=1)
12
+ text = tokenizer.decode(outputs[0], skip_special_tokens=True)
13
+ return text
14
+
15
+ # Streamlit app
16
+ st.title('Blog Post Generator')
17
+ topic = st.text_input('Enter a topic:')
18
+ if topic:
19
+ blogpost = generate_blogpost(topic)
20
+ st.write(blogpost)