Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -2,30 +2,25 @@ import openai
|
|
2 |
import gradio as gr
|
3 |
import os
|
4 |
|
5 |
-
#OpenAi call
|
6 |
def gpt3(texts):
|
7 |
-
openai.api_key
|
8 |
-
response =
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
)
|
18 |
-
x = response.choices[0].
|
19 |
-
|
20 |
return x
|
21 |
|
22 |
-
# Function to elicit sql response from model
|
23 |
def greet(prompt):
|
24 |
-
txt=
|
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()
|
|
|
2 |
import gradio as gr
|
3 |
import os
|
4 |
|
|
|
5 |
def gpt3(texts):
|
6 |
+
client = openai.OpenAI(api_key=os.environ["Secret"]) # Create client instance
|
7 |
+
response = client.chat.completions.create( # Use chat completions
|
8 |
+
model="gpt-4-turbo-preview", # Updated model name
|
9 |
+
messages=[{"role": "user", "content": texts}], # New messages format
|
10 |
+
temperature=0,
|
11 |
+
max_tokens=750,
|
12 |
+
top_p=1,
|
13 |
+
frequency_penalty=0.0,
|
14 |
+
presence_penalty=0.0,
|
15 |
+
stop=[";", "/*", "</code>"]
|
16 |
)
|
17 |
+
x = response.choices[0].message.content # Updated response structure
|
|
|
18 |
return x
|
19 |
|
|
|
20 |
def greet(prompt):
|
21 |
+
txt= f'''/*Prompt: {prompt}*/ \n'''
|
22 |
sql = gpt3(txt)
|
23 |
return sql
|
24 |
|
25 |
+
iface = gr.Interface(greet, inputs = ["text"])
|
|
|
|
|
26 |
iface.launch()
|