Words_To_SQL / app.py
Curranj's picture
Update app.py
1f79e6d
raw
history blame
No virus
882 Bytes
import openai
import gradio as gr
def gpt3(texts):
openai.api_key ="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"
response = openai.Completion.create(
engine="code-davinci-002",
prompt= texts,
temperature=0,
max_tokens=750,
top_p=1,
frequency_penalty=0.0,
presence_penalty=0.0,
stop = (";", "/*")
)
x = response.choices[0].text
return x
# create a UI using gradio that takes in a text name and a text prompt, which then is displayed back to the user
def greet( prompt):
txt= (f'''/*Prompt: {prompt}*/ \n --SQL Code:''')
sql = gpt3(txt)
return sql
#the scrip variable is a string of python code with a sql query in it. execute the code keep the result in a variable
iface = gr.Interface(greet, inputs = ["text"], outputs = "text")
iface.launch()