Spaces:
Runtime error
Runtime error
File size: 1,684 Bytes
0b540e1 5c2d53d ef5aca4 0b540e1 ef5aca4 6815209 d38987e 73a3947 daeb276 5c2d53d 0b540e1 4d6e76c 5f669c2 4d6e76c 5f669c2 adc5ece 6815209 adc5ece 6815209 b4a2738 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
import sys
import time
import os
import streamlit as st
import concurrent.futures
from random import randint
st.markdown("<h1 style='text-align: center; color: white;'>Generate intresting stories with GPT</h1>", unsafe_allow_html=True)
st.markdown('')
st.markdown('')
# initializing session_state
os.system('pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cpu')
os.system('pip install transformers')
from transformers import pipeline, set_seed
generator = pipeline('text-generation', model='openai-gpt')
def generate(initial_text, length=10, return_sequences=1):
set_seed(randint(1,1000))
result = generator(initial_text, max_length = length, num_return_sequences = return_sequences)
return result[0]["generated_text"]
def slice(text, mak_length=10):
return text[-mak_length:]
def type_text(text):
for letter in text:
sys.stdout.write(letter)
time.sleep(0)
#text = input("Enter something to begin with... ")
#print(".\n.\n.\nGenerating\n.\n.\n.")
#for _ in range(50):
#result = generate(text)
#text=slice(result)
#with concurrent.futures.ThreadPoolExecutor() as executor:
# executor.submit(type_text, result.replace(text,""))
#Streamlit
text = st.text_input('Enter something to begin with...', placeholder='I look at her, then i realised', key="placeholder")
if text:
st.write("Generating...", text)
st.write("", text)
for _ in range(50):
result = generate(text)
text=slice(result)
st.write(text, text)
#with concurrent.futures.ThreadPoolExecutor() as executor:
# executor.submit(type_text, result.replace(text,""))
|