Spaces:
Runtime error
Runtime error
| import openai | |
| import gradio as gr | |
| import os | |
| #OpenAi call | |
| def gpt3(texts): | |
| openai.api_key = os.environ["Secret"] | |
| response = openai.Completion.create( | |
| engine="text-davinci-002", | |
| prompt= texts, | |
| temperature=0, | |
| max_tokens=750, | |
| top_p=1, | |
| frequency_penalty=0.0, | |
| presence_penalty=0.0, | |
| stop = (";", "/*", "</code>") | |
| ) | |
| x = response.choices[0].text | |
| return x | |
| # Function to elicit sql response from model | |
| def greet(prompt): | |
| food= (f'''Here we will share a best guess for the predominant ingredients in the following food /*Food: {prompt}*/ \n —-Here is a list of the ingredients in the food item:\n''') | |
| ingred = gpt3(food) | |
| total = (f'''Expert one sentence summary and rating (on a scale of 1/10, with 10 having no impact) of the food and ingredients comparative climate impact, from rationalist climate perspective /*Food, ingredients: {prompt},{ingred}*/ \n —-Impact Summary and Climate Score:\n''') | |
| score = gpt3(total) | |
| return score | |
| #Code to set up Gradio UI | |
| iface = gr.Interface(greet, inputs = ["text"], outputs = ["text"],title="Food Impact Analysis", description="Get a climate analysis back from any food!") | |
| iface.launch() |