Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Prompt: Create a streamlit program that uses Text generation with a huggingface model
|
2 |
+
import streamlit as st
|
3 |
+
from transformers import pipeline
|
4 |
+
|
5 |
+
# Load the Hugging Face model for text generation
|
6 |
+
generator = pipeline("text-generation", model="gpt2")
|
7 |
+
|
8 |
+
# Set the maximum length of generated text
|
9 |
+
MAX_LENGTH = 100
|
10 |
+
|
11 |
+
# Create a Streamlit app
|
12 |
+
st.title("Text Generator")
|
13 |
+
|
14 |
+
# Add a text input for the user to provide a prompt for the generated text
|
15 |
+
prompt = st.text_input("Enter a prompt for the generated text:")
|
16 |
+
|
17 |
+
# Generate text based on the user's prompt
|
18 |
+
if prompt:
|
19 |
+
generated_text = generator(prompt, max_length=MAX_LENGTH, do_sample=True)[0]["generated_text"]
|
20 |
+
st.write(generated_text)
|