YasirAbdali commited on
Commit
888b62c
·
verified ·
1 Parent(s): fdbdc93

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -5
app.py CHANGED
@@ -8,13 +8,27 @@ tokenizer = AutoTokenizer.from_pretrained(model_name)
8
  model = AutoModelForCausalLM.from_pretrained(model_name)
9
 
10
  # Streamlit app
11
- st.title("Blog Post Generator")
12
 
13
  # User input
14
- prompt = st.text_area("Enter a blog post topic or starting sentence:")
15
- max_length = st.slider("Maximum length of generated text:", min_value=50, max_value=500, value=200, step=50)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
- if prompt:
18
  # Tokenize input
19
  input_ids = tokenizer.encode(prompt, return_tensors="pt")
20
 
@@ -32,5 +46,14 @@ if prompt:
32
 
33
  # Decode and display generated text
34
  generated_text = tokenizer.decode(output[0], skip_special_tokens=True)
 
35
  st.subheader("Generated Blog Post:")
36
- st.write(generated_text)
 
 
 
 
 
 
 
 
 
8
  model = AutoModelForCausalLM.from_pretrained(model_name)
9
 
10
  # Streamlit app
11
+ st.title("Formatted Blog Post Generator")
12
 
13
  # User input
14
+ topic = st.text_input("Enter a blog post topic:")
15
+ max_length = st.slider("Maximum length of generated text:", min_value=100, max_value=2000, value=500, step=50)
16
+
17
+ if topic:
18
+ # Construct a detailed prompt
19
+ prompt = f"""Write a well-formatted blog post about {topic}. Use the following structure:
20
+
21
+ 1. Start with a main title using a single '#' symbol.
22
+ 2. Include an introduction paragraph.
23
+ 3. Use '##' for subheadings.
24
+ 4. Use bullet points ('-') for lists.
25
+ 5. Separate paragraphs with blank lines.
26
+ 6. End with a conclusion paragraph.
27
+
28
+ Here's the blog post:
29
+
30
+ # """
31
 
 
32
  # Tokenize input
33
  input_ids = tokenizer.encode(prompt, return_tensors="pt")
34
 
 
46
 
47
  # Decode and display generated text
48
  generated_text = tokenizer.decode(output[0], skip_special_tokens=True)
49
+
50
  st.subheader("Generated Blog Post:")
51
+ st.markdown(generated_text)
52
+
53
+ # Option to download the blog post
54
+ st.download_button(
55
+ label="Download Blog Post",
56
+ data=generated_text,
57
+ file_name="generated_blog_post.md",
58
+ mime="text/markdown"
59
+ )