Spaces:
Runtime error
Runtime error
Sander Land
commited on
Commit
•
f66ca1f
1
Parent(s):
5c12e3d
tokens
Browse files- app.py +7 -5
- requirements.txt +1 -0
app.py
CHANGED
@@ -6,17 +6,17 @@ import cohere
|
|
6 |
import streamlit as st
|
7 |
|
8 |
DEFAULT_DISH = "herring and banana quesadillas"
|
|
|
9 |
|
10 |
logger = logging.getLogger('recipe-logger')
|
11 |
|
12 |
|
13 |
-
def command(co, prompt, model='command-xlarge-20221108', max_tokens=
|
14 |
gens = co.generate(prompt, model=model, max_tokens=max_tokens, return_likelihoods='GENERATION', *args, **kwargs)
|
15 |
return sorted(gens, key=lambda g: -g.likelihood)
|
16 |
|
17 |
|
18 |
def space(num_lines=1):
|
19 |
-
"""Adds empty lines to the Streamlit app."""
|
20 |
for _ in range(num_lines):
|
21 |
st.write("")
|
22 |
|
@@ -38,12 +38,14 @@ st.write("What would you like a recipe for?")
|
|
38 |
|
39 |
with st.form("form"):
|
40 |
dish = st.text_input("Dish", placeholder=DEFAULT_DISH)
|
41 |
-
options = st.multiselect("Special requests",
|
42 |
-
|
|
|
|
|
43 |
submitted = st.form_submit_button("Generate Recipe!")
|
44 |
|
45 |
if submitted:
|
46 |
-
dish = dish or DEFAULT_DISH
|
47 |
co = cohere.Client(api_key=os.environ['CO_API_KEY'])
|
48 |
prompt = f"Give a recipe for {dish}."
|
49 |
if options:
|
|
|
6 |
import streamlit as st
|
7 |
|
8 |
DEFAULT_DISH = "herring and banana quesadillas"
|
9 |
+
MAX_TOKENS = 300
|
10 |
|
11 |
logger = logging.getLogger('recipe-logger')
|
12 |
|
13 |
|
14 |
+
def command(co, prompt, model='command-xlarge-20221108', max_tokens=MAX_TOKENS, *args, **kwargs):
|
15 |
gens = co.generate(prompt, model=model, max_tokens=max_tokens, return_likelihoods='GENERATION', *args, **kwargs)
|
16 |
return sorted(gens, key=lambda g: -g.likelihood)
|
17 |
|
18 |
|
19 |
def space(num_lines=1):
|
|
|
20 |
for _ in range(num_lines):
|
21 |
st.write("")
|
22 |
|
|
|
38 |
|
39 |
with st.form("form"):
|
40 |
dish = st.text_input("Dish", placeholder=DEFAULT_DISH)
|
41 |
+
options = st.multiselect("Special requests", [
|
42 |
+
"extra delicious", "vegan", "gluten-free", "sugar-free", "dairy-free", "nut-free", "low-calorie", "low-fat",
|
43 |
+
"low-sugar"
|
44 |
+
])
|
45 |
submitted = st.form_submit_button("Generate Recipe!")
|
46 |
|
47 |
if submitted:
|
48 |
+
dish = (dish or DEFAULT_DISH).strip()
|
49 |
co = cohere.Client(api_key=os.environ['CO_API_KEY'])
|
50 |
prompt = f"Give a recipe for {dish}."
|
51 |
if options:
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
cohere==2.8.0
|