pbjs_gpt2 / app.py
PeterBrendan's picture
Create app.py
20fefb1
raw
history blame
832 Bytes
import streamlit as st
from transformers import pipeline
@st.cache(allow_output_mutation=True)
def load_model():
return pipeline("text-generation", model="pbjs_gpt2")
def main():
st.title("Hugging Face Model Demo")
st.write("Enter some text and get generated text as output.")
# Create a text input field for user input
user_input = st.text_input("Enter text:", "")
# Check if the user input is empty
if user_input:
# Load the Hugging Face model
generator = load_model()
# Generate text based on user input
generated_text = generator(user_input, max_length=100, num_return_sequences=1)[0]["generated_text"]
# Display the generated text
st.write("Generated Text:")
st.write(generated_text)
# Run the app
if __name__ == "__main__":
main()