Mohuu0601 commited on
Commit
d3d7810
·
verified ·
1 Parent(s): 7369f97

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -0
app.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import pipeline
3
+
4
+ # Step 1: Load the Hugging Face model
5
+ @st.cache_resource
6
+ def load_model():
7
+ return pipeline("text-generation", model="gpt2") # Replace 'gpt2' with another model if needed
8
+
9
+ generator = load_model()
10
+
11
+ # Step 2: Design the Streamlit layout
12
+ st.title("Hugging Face Text Generator")
13
+ st.write("Generate creative text using GPT-2!")
14
+
15
+ # Get user input
16
+ user_input = st.text_area("Enter a prompt for text generation:", "Once upon a time")
17
+
18
+ # Generate text when the button is clicked
19
+ if st.button("Generate Text"):
20
+ with st.spinner("Generating..."):
21
+ results = generator(user_input, max_length=50, num_return_sequences=1)
22
+ generated_text = results[0]["generated_text"]
23
+ st.subheader("Generated Text:")
24
+ st.write(generated_text)
25
+
26
+ st.write("Powered by Streamlit and Hugging Face 🤗")