adrianpierce commited on
Commit
641d571
1 Parent(s): 63107d9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -31
app.py CHANGED
@@ -8,40 +8,37 @@ import pandas as pd
8
 
9
  openai.api_key = st.secrets["open_ai_key"]
10
 
11
- def get_response(context, prompt):
12
-
13
-
14
- return gpt_response
15
-
16
  uploaded_file = st.file_uploader("Choose a file")
17
  if uploaded_file is not None:
18
-
19
 
20
-
21
  image = Image.open(uploaded_file)
22
- with st.expander('Preview uploaded image', expanded=False):
 
23
  st.image(image)
24
- extractedInformation = pytesseract.image_to_string(image)
25
- st.write(extractedInformation)
26
-
27
- context = '''parse the unstructured input of a cooking recipe into a valid JSON array of objects in the following format:
28
- [{
29
- "recipe_name": "the name of the recipe expressed as a string",
30
- "recipe_ingredients": "list of ingredients specified in the recipe expressed as string",
31
- "recipe_steps": "list of steps to cook the recipe expressed as a string"
32
- }]'''
33
-
34
- gpt_response = openai.ChatCompletion.create(
35
- model="gpt-3.5-turbo",
36
- messages=[
37
- {"role": "system", "content": context},
38
- {"role": "user", "content": extractedInformation}
39
- ],
40
- temperature=0.2,
41
- max_tokens=1000
42
- )
43
-
44
- st.json((json.loads(gpt_response['choices'][0]['message']['content'])))
45
- cost = gpt_response['usage']["prompt_tokens"]*(0.0015/1000) + gpt_response['usage']["completion_tokens"]*(0.002/1000)
46
- st.write(f'Cost for query was approx ${cost}')
 
 
 
47
 
 
8
 
9
  openai.api_key = st.secrets["open_ai_key"]
10
 
 
 
 
 
 
11
  uploaded_file = st.file_uploader("Choose a file")
12
  if uploaded_file is not None:
 
13
 
 
14
  image = Image.open(uploaded_file)
15
+
16
+ with st.expander('Uploaded image', expanded=False):
17
  st.image(image)
18
+
19
+ with st.expander('Raw OCR', expanded=False):
20
+ extractedInformation = pytesseract.image_to_string(image)
21
+ st.write(extractedInformation)
22
+
23
+ with st.expander('GPT cleaned output', expanded=True):
24
+ context = '''parse the unstructured input of a cooking recipe into a valid JSON array of objects in the following format:
25
+ [{
26
+ "recipe_name": "the name of the recipe expressed as a string",
27
+ "recipe_ingredients": "list of ingredients specified in the recipe expressed as string",
28
+ "recipe_steps": "list of steps to cook the recipe expressed as a string"
29
+ }]'''
30
+
31
+ gpt_response = openai.ChatCompletion.create(
32
+ model="gpt-3.5-turbo",
33
+ messages=[
34
+ {"role": "system", "content": context},
35
+ {"role": "user", "content": extractedInformation}
36
+ ],
37
+ temperature=0.2,
38
+ max_tokens=1000
39
+ )
40
+
41
+ st.json((json.loads(gpt_response['choices'][0]['message']['content'])))
42
+ cost = gpt_response['usage']["prompt_tokens"]*(0.0015/1000) + gpt_response['usage']["completion_tokens"]*(0.002/1000)
43
+ st.write(f'Cost for query was approx ${cost}')
44