File size: 1,661 Bytes
19f8492
 
 
 
 
 
6e64066
19f8492
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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)