File size: 1,437 Bytes
4ddaa8e
 
 
2575900
cc5676d
 
 
 
 
 
 
 
 
 
4ddaa8e
 
 
cc5676d
2575900
4ddaa8e
3024c56
 
2575900
4ddaa8e
 
cc5676d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import pytesseract
from io import StringIO
from PIL import Image
import json
import openai
import pandas as pd

openai.api_key = st.secrets["open_ai_key"]

def get_response(context, prompt):
    

    return gpt_response

uploaded_file = st.file_uploader("Choose a file")
if uploaded_file is not None:

    

    #image = Image.open(uploaded_file)
    #st.image(image, caption='Sunrise by the mountains')
    extractedInformation = pytesseract.image_to_string(image)
    st.write(extractedInformation)

    context = '''parse the unstructured input of a cooking recipe into a valid JSON array of objects in the following format:
    [{
    "recipe_name": "the name of the recipe expressed as a string",
    "recipe_ingredients": "list of ingredients specified in the recipe expressed as string",
    "recipe_steps": "list of steps to cook the recipe expressed as a string"
    }]'''

    gpt_response = openai.ChatCompletion.create(
        model="gpt-3.5-turbo",
        messages=[
            {"role": "system", "content": context},
            {"role": "user", "content": extractedInformation}
        ],
        temperature=0.2,
        max_tokens=1000
    )

    st.json((json.loads(gpt_response['choices'][0]['message']['content'])))
    cost = gpt_response['usage']["prompt_tokens"]*(0.0015/1000) + gpt_response['usage']["completion_tokens"]*(0.002/1000)
    st.write(f'Cost for query was approx ${cost}')