-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
49 lines (33 loc) · 1.04 KB
/
main.py
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
import os
import ai21
import streamlit as st
from dotenv import load_dotenv
# Load secrets
load_dotenv()
API_KEY = os.getenv("AI21_LABS_API_KEY")
ai21.api_key = API_KEY
PROMPT = "Based on the description given, name the sport.\nDescription: {description}\n Sport name: "
# Initialization
if "output" not in st.session_state:
st.session_state["output"] = "Output:"
def guess_sport(inp):
if not len(inp):
return None
prompt = PROMPT.format(description=inp)
response = ai21.Completion.execute(
model="j2-grande-instruct",
prompt=prompt,
temperature=0.5,
minTokens=1,
maxTokens=15,
numResults=1,
)
st.session_state["output"] = response.completions[0].data.text
st.balloons()
st.title("The Sports Guesser")
st.write(
"This is a simple **Streamlit** app that generates Sport Name based on given description"
)
inp = st.text_area("Enter your description here", height=100)
st.button("Gue" "ss", on_click=guess_sport(inp))
st.write(f"Answer: {st.session_state.output}")