Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,33 +1,102 @@
|
|
| 1 |
import openai
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
import gradio as gr
|
|
|
|
|
|
|
| 3 |
import os
|
| 4 |
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
#OpenAi call
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
def greet(prompt):
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
|
| 31 |
#Code to set up Gradio UI
|
| 32 |
-
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import openai
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
|
| 6 |
import gradio as gr
|
| 7 |
+
|
| 8 |
+
|
| 9 |
import os
|
| 10 |
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
|
| 16 |
|
| 17 |
#OpenAi call
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def gpt3(texts):
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
openai.api_key = os.environ["Secret"]
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
response = openai.Completion.create(
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
engine="code-davinci-002",
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
prompt= texts,
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
temperature=0,
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
max_tokens=750,
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
top_p=1,
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
frequency_penalty=0.0,
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
presence_penalty=0.0,
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
stop = (";", "/*", "</code>")
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
)
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
x = response.choices[0].text
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
return x
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
# Function to elicit sql response from model
|
| 71 |
+
|
| 72 |
+
|
| 73 |
def greet(prompt):
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
txt= (f'''/*Prompt: {prompt}*/ \n —-SQL Code:\n''')
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
sql = gpt3(txt)
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
return sql
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
|
| 93 |
|
| 94 |
|
| 95 |
#Code to set up Gradio UI
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
iface = gr.Interface(greet, inputs = ["text"], outputs = "text",title="Natural Language to SQL", description="Enter any prompt and get a SQL statement back! For better results, give it more context")
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
iface.launch()
|
| 102 |
+
|