StoryWriter / app.py
yash108coolboy's picture
Update app.py
e37b04e verified
raw
history blame contribute delete
997 Bytes
import streamlit as st
# Set the title of the web app
st.title("Text and Token Input App")
# Input for the user's prompt
prompt = st.text_area("Enter a prompt above 15 words:")
# Input for the number of tokens to be generated
num_tokens = st.number_input("Enter the number of tokens to be generated:", min_value=1, step=1)
# Function to calculate the length of the string and the sum of the length and number of tokens
def calculate_length_and_sum(prompt, num_tokens):
prompt_length = len(prompt.split())
total_sum = prompt_length + num_tokens
return prompt_length, total_sum
# Button to perform the calculation
if st.button("Calculate"):
if len(prompt.split()) < 15:
st.warning("Please enter a prompt with more than 15 words.")
else:
prompt_length, total_sum = calculate_length_and_sum(prompt, num_tokens)
st.write(f"Length of the prompt: {prompt_length}")
st.write(f"Sum of the length of the prompt and the number of tokens: {total_sum}")