Skip to content
This repository was archived by the owner on Jan 16, 2025. It is now read-only.

Commit 9446835

Browse files
committed
update notebooks and examples for LLMU
1 parent e92ff50 commit 9446835

17 files changed

+3861
-9312
lines changed

notebooks/llmu/Classify_Endpoint.ipynb

Lines changed: 279 additions & 291 deletions
Large diffs are not rendered by default.

notebooks/llmu/End_To_End_Wikipedia_Search.ipynb

Lines changed: 1058 additions & 1114 deletions
Large diffs are not rendered by default.

notebooks/llmu/Topic_Modeling.ipynb

Lines changed: 0 additions & 1305 deletions
This file was deleted.

notebooks/llmu/Visualizing_Text_Embeddings.ipynb

Lines changed: 1250 additions & 1494 deletions
Large diffs are not rendered by default.

notebooks/llmu/What_Is_Similarity_Between_Sentences.ipynb

Lines changed: 407 additions & 292 deletions
Large diffs are not rendered by default.

notebooks/llmu/What_is_Semantic_Search.ipynb

Lines changed: 716 additions & 981 deletions
Large diffs are not rendered by default.
Binary file not shown.
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
import cohere
2+
import streamlit as st
3+
import os
4+
import textwrap
5+
import json
6+
7+
# Set up Cohere client
8+
co = cohere.Client(os.environ["COHERE_API_KEY"]) # Get your API key: https://dashboard.cohere.com/api-keys
9+
10+
def generate_idea(industry, temperature):
11+
"""
12+
Generate startup idea given an industry name
13+
Arguments:
14+
industry(str): the industry name
15+
temperature(str): the Generate model `temperature` value
16+
Returns:
17+
response(str): the startup idea
18+
"""
19+
prompt = f"""
20+
Generate a startup idea given the industry. Return the startup idea and without additional commentary.
21+
22+
## Examples
23+
Industry: Workplace
24+
Startup Idea: A platform that generates slide deck contents automatically based on a given outline
25+
26+
Industry: Home Decor
27+
Startup Idea: An app that calculates the best position of your indoor plants for your apartment
28+
29+
Industry: Healthcare
30+
Startup Idea: A hearing aid for the elderly that automatically adjusts its levels and with a battery lasting a whole week
31+
32+
Industry: Education
33+
Startup Idea: An online primary school that lets students mix and match their own curriculum based on their interests and goals
34+
35+
## Your Task
36+
Industry: {industry}
37+
Startup Idea:"""
38+
39+
# Call the Cohere Chat endpoint
40+
response = co.chat(
41+
message=prompt,
42+
model='command-r',
43+
temperature=temperature,
44+
preamble="")
45+
46+
return response.text
47+
48+
def generate_name(idea, temperature):
49+
"""
50+
Generate startup name given a startup idea
51+
Arguments:
52+
idea(str): the startup idea
53+
temperature(str): the Generate model `temperature` value
54+
Returns:
55+
response(str): the startup name
56+
"""
57+
prompt= f"""
58+
Generate a startup name given the startup idea. Return the startup name and without additional commentary.
59+
60+
## Examples
61+
Startup Idea: A platform that generates slide deck contents automatically based on a given outline
62+
Startup Name: Deckerize
63+
64+
Startup Idea: An app that calculates the best position of your indoor plants for your apartment
65+
Startup Name: Planteasy
66+
67+
Startup Idea: A hearing aid for the elderly that automatically adjusts its levels and with a battery lasting a whole week
68+
Startup Name: Hearspan
69+
70+
Startup Idea: An online primary school that lets students mix and match their own curriculum based on their interests and goals
71+
Startup Name: Prime Age
72+
73+
## Your Task
74+
Startup Idea: {idea}
75+
Startup Name:"""
76+
# Call the Cohere Chat endpoint
77+
response = co.chat(
78+
message=prompt,
79+
model='command-r',
80+
temperature=temperature,
81+
preamble="")
82+
83+
return response.text
84+
85+
# The front end code starts here
86+
87+
st.title("🚀 Startup Idea Generator")
88+
89+
form = st.form(key="user_settings")
90+
with form:
91+
st.write("Enter an industry name [Example: Productivity, Food, Sports] ")
92+
# User input - Industry name
93+
industry_input = st.text_input("Industry", key = "industry_input")
94+
95+
# Create a two-column view
96+
col1, col2 = st.columns(2)
97+
with col1:
98+
# User input - The number of ideas to generate
99+
num_input = st.slider(
100+
"Number of ideas",
101+
value = 3,
102+
key = "num_input",
103+
min_value=1,
104+
max_value=10,
105+
help="Choose to generate between 1 to 10 ideas")
106+
with col2:
107+
# User input - The 'temperature' value representing the level of creativity
108+
creativity_input = st.slider(
109+
"Creativity", value = 0.5,
110+
key = "creativity_input",
111+
min_value=0.1,
112+
max_value=0.9,
113+
help="Lower values generate more “predictable” output, higher values generate more “creative” output")
114+
# Submit button to start generating ideas
115+
generate_button = form.form_submit_button("Generate Idea")
116+
117+
if generate_button:
118+
if industry_input == "":
119+
st.error("Industry field cannot be blank")
120+
else:
121+
my_bar = st.progress(0.05)
122+
st.subheader("Startup Ideas:")
123+
124+
for i in range(num_input):
125+
st.markdown("""---""")
126+
startup_idea = generate_idea(industry_input,creativity_input)
127+
startup_name = generate_name(startup_idea,creativity_input)
128+
st.markdown("##### " + startup_name)
129+
st.write(startup_idea)
130+
my_bar.progress((i+1)/num_input)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Startup Idea Generator App
2+
3+
This is the code companion for the LLMU chapter: [Deploying with Streamlit](https://docs.cohere.com/docs/deploying-with-streamlit)
4+
5+
This example demonstrated how, using Cohere and Streamlit, you can quickly create a basic prototype of an LLM application.
6+
7+
Before running the app, make sure to install the required dependencies:
8+
```bash
9+
$ pip install -r requirements.txt
10+
```
11+
12+
To run the app, enter:
13+
```bash
14+
$ streamlit run app.py
15+
```

0 commit comments

Comments
 (0)