christinestraubdev commited on
Commit
ee0f2bd
1 Parent(s): ce02c5b

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -0
app.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import openai
2
+ import gradio as gr
3
+ import os
4
+
5
+
6
+ # OpenAi call
7
+ def gpt3(texts):
8
+ openai.api_key = os.environ["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"]
9
+ response = openai.Completion.create(
10
+ engine="text-davinci-003",
11
+ prompt=texts,
12
+ temperature=0,
13
+ max_tokens=750,
14
+ top_p=1,
15
+ frequency_penalty=0.0,
16
+ presence_penalty=0.0,
17
+ stop=(";", "/*", "</code>")
18
+ )
19
+ x = response.choices[0].text
20
+
21
+ return x
22
+
23
+
24
+ # Function to elicit sql response from model
25
+ def greet(prompt):
26
+ txt = (f'''/*Prompt: {prompt}*/ \n —-SQL Code:\n''')
27
+ sql = gpt3(txt)
28
+ return sql
29
+
30
+
31
+ # Code to set up Gradio UI
32
+ iface = gr.Interface(greet, inputs=["text"], outputs="text", title="Natural Language to SQL",
33
+ description="Enter any prompt and get a SQL statement back! For better results, give it more context")
34
+ iface.launch()