Spaces:
Sleeping
Sleeping
Commit
·
20fefb1
1
Parent(s):
dd9e84d
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
@st.cache(allow_output_mutation=True)
|
5 |
+
def load_model():
|
6 |
+
return pipeline("text-generation", model="pbjs_gpt2")
|
7 |
+
|
8 |
+
def main():
|
9 |
+
st.title("Hugging Face Model Demo")
|
10 |
+
st.write("Enter some text and get generated text as output.")
|
11 |
+
|
12 |
+
# Create a text input field for user input
|
13 |
+
user_input = st.text_input("Enter text:", "")
|
14 |
+
|
15 |
+
# Check if the user input is empty
|
16 |
+
if user_input:
|
17 |
+
# Load the Hugging Face model
|
18 |
+
generator = load_model()
|
19 |
+
|
20 |
+
# Generate text based on user input
|
21 |
+
generated_text = generator(user_input, max_length=100, num_return_sequences=1)[0]["generated_text"]
|
22 |
+
|
23 |
+
# Display the generated text
|
24 |
+
st.write("Generated Text:")
|
25 |
+
st.write(generated_text)
|
26 |
+
|
27 |
+
# Run the app
|
28 |
+
if __name__ == "__main__":
|
29 |
+
main()
|