Curranj commited on
Commit
20eb013
·
1 Parent(s): c4cefd4

Update app.py

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