Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import openai
|
2 |
+
import gradio as gr
|
3 |
+
import os
|
4 |
+
|
5 |
+
#OpenAi call
|
6 |
+
def gpt3(texts):
|
7 |
+
openai.api_key = os.environ["Secret"]
|
8 |
+
response = openai.Completion.create(
|
9 |
+
engine="text-davinci-002",
|
10 |
+
prompt= texts,
|
11 |
+
temperature=0,
|
12 |
+
max_tokens=750,
|
13 |
+
top_p=1,
|
14 |
+
frequency_penalty=0.0,
|
15 |
+
presence_penalty=0.0,
|
16 |
+
stop = (";", "/*", "</code>")
|
17 |
+
)
|
18 |
+
x = response.choices[0].text
|
19 |
+
|
20 |
+
return x
|
21 |
+
|
22 |
+
# Function to elicit sql response from model
|
23 |
+
def greet(prompt):
|
24 |
+
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''')
|
25 |
+
|
26 |
+
ingred = gpt3(food)
|
27 |
+
|
28 |
+
|
29 |
+
|
30 |
+
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''')
|
31 |
+
score = gpt3(total)
|
32 |
+
return score
|
33 |
+
|
34 |
+
|
35 |
+
#Code to set up Gradio UI
|
36 |
+
iface = gr.Interface(greet, inputs = ["text"], outputs = ["text"],title="Food Impact Analysis", description="Get a climate analysis back from any food!")
|
37 |
+
iface.launch()
|