Siri23 commited on
Commit
268b556
·
verified ·
1 Parent(s): f314669

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -0
app.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import pipeline
2
+ import streamlit as st
3
+
4
+ # Load the text generation pipeline
5
+ pipe = pipeline("text-generation", model="meta-llama/Meta-Llama-3-8B")
6
+
7
+ def generate_blog(topic, no_words):
8
+ # Create the prompt
9
+ prompt = f"Write a blog on the topic '{topic}' within {no_words} words."
10
+
11
+ # Generate the blog content
12
+ result = pipe(prompt, max_length=int(no_words), num_return_sequences=1)
13
+
14
+ # Extract the generated text
15
+ blog_content = result[0]['generated_text']
16
+ return blog_content
17
+
18
+ # Streamlit app
19
+ st.set_page_config(page_title="Blog Generator", page_icon="📝")
20
+ st.title("Blog Content Generator 📝")
21
+
22
+ # Input fields
23
+ topic = st.text_input("Enter the Blog Topic")
24
+ no_words = st.number_input("Enter the Number of Words", min_value=50, max_value=1000, value=200, step=50)
25
+
26
+ if st.button("Generate Blog"):
27
+ if topic and no_words:
28
+ with st.spinner("Generating blog content..."):
29
+ blog_content = generate_blog(topic, no_words)
30
+ st.subheader("Generated Blog Content")
31
+ st.write(blog_content)
32
+ else:
33
+ st.error("Please provide both the blog topic and the number of words.")