petals / app.py
ybelkada's picture
Update app.py
6e64066
raw
history blame
1.66 kB
import requests
import streamlit as st
from utils_display import HEADER, SIDE_BAR_TEXT, write_incremental, i_am_feeling_lucky
st.markdown(HEADER, unsafe_allow_html=True)
st.markdown("![Alt Text](https://camo.githubusercontent.com/473dd9f992924d27457650251786464f72e54121ac6e9210add0f483ca849277/68747470733a2f2f692e696d6775722e636f6d2f3765523750616e2e706e67)")
st.sidebar.image(
"https://assets.website-files.com/6139f3cdcbbff3a68486761d/613cd8997b270da063e230c5_Tekengebied%201-p-2000.png",
use_column_width=True
)
st.sidebar.markdown(
SIDE_BAR_TEXT
)
MAX_LEN = 100
max_length = st.sidebar.slider("Maximum generation length", 1, MAX_LEN, 20)
# TODO: use the correct URL once it is ready
# url = (
# f"https://hf.space/embed/bigscience/distributed-bloom-api/+/api/predict/"
# )
url = (
f"https://hf.space/embed/ybelkada/bloom-1b3-gen/+/api/predict/"
)
text_input = st.text_area(' Write your prompt below ๐Ÿ”Ž', height=50)
col1, col2, col3 = st.columns(3)
with col1:
button_pushed = st.button("Let's generate!")
with col2:
lucky_button = st.button("I am feeling lucky")
with col3:
method_button = st.button("How does the method work?")
text_placeholder = st.empty()
if lucky_button:
text_input = i_am_feeling_lucky()
button_pushed = True
if button_pushed:
if text_input != '':
r = requests.post(
url=url, json={"data": [text_input, max_length, 0.6, True, 5, 42]}
)
generated_text = r.json()["data"][0]
write_incremental(text_input + generated_text, text_placeholder)
else:
write_incremental("Write some text above and try again :-)", text_placeholder)