Spaces:
Sleeping
Sleeping
maheshwarligade
commited on
Commit
•
ac51c30
1
Parent(s):
4837346
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import openai
|
2 |
+
import gradio as gr
|
3 |
+
import os
|
4 |
+
|
5 |
+
#OpenAi call for davinci model
|
6 |
+
def gpt3(texts):
|
7 |
+
openai.api_key = os.environ["Secret"]
|
8 |
+
response = openai.Completion.create(
|
9 |
+
engine="text-davinci-003",
|
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 |
+
txt= (f'''/*Prompt: {prompt}*/ \n —-SQL Code:\n''')
|
25 |
+
sql = gpt3(txt)
|
26 |
+
return sql
|
27 |
+
|
28 |
+
|
29 |
+
#Code to set up Gradio UI
|
30 |
+
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")
|
31 |
+
iface.launch()
|