Spaces:
Sleeping
Sleeping
adrianpierce
commited on
Commit
•
cc5676d
1
Parent(s):
57cd3ca
Update app.py
Browse files
app.py
CHANGED
@@ -2,9 +2,20 @@ import streamlit as st
|
|
2 |
import pytesseract
|
3 |
from io import StringIO
|
4 |
from PIL import Image
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
uploaded_file = st.file_uploader("Choose a file")
|
7 |
if uploaded_file is not None:
|
|
|
8 |
|
9 |
|
10 |
#image = Image.open(uploaded_file)
|
@@ -12,3 +23,24 @@ if uploaded_file is not None:
|
|
12 |
extractedInformation = pytesseract.image_to_string(image)
|
13 |
st.write(extractedInformation)
|
14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
import pytesseract
|
3 |
from io import StringIO
|
4 |
from PIL import Image
|
5 |
+
import json
|
6 |
+
import openai
|
7 |
+
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)
|
|
|
23 |
extractedInformation = pytesseract.image_to_string(image)
|
24 |
st.write(extractedInformation)
|
25 |
|
26 |
+
context = '''parse the unstructured input of a cooking recipe into a valid JSON array of objects in the following format:
|
27 |
+
[{
|
28 |
+
"recipe_name": "the name of the recipe expressed as a string",
|
29 |
+
"recipe_ingredients": "list of ingredients specified in the recipe expressed as string",
|
30 |
+
"recipe_steps": "list of steps to cook the recipe expressed as a string"
|
31 |
+
}]'''
|
32 |
+
|
33 |
+
gpt_response = openai.ChatCompletion.create(
|
34 |
+
model="gpt-3.5-turbo",
|
35 |
+
messages=[
|
36 |
+
{"role": "system", "content": context},
|
37 |
+
{"role": "user", "content": extractedInformation}
|
38 |
+
],
|
39 |
+
temperature=0.2,
|
40 |
+
max_tokens=1000
|
41 |
+
)
|
42 |
+
|
43 |
+
st.json((json.loads(gpt_response['choices'][0]['message']['content'])))
|
44 |
+
cost = gpt_response['usage']["prompt_tokens"]*(0.0015/1000) + gpt_response['usage']["completion_tokens"]*(0.002/1000)
|
45 |
+
st.write(f'Cost for query was approx ${cost}')
|
46 |
+
|