Curranj commited on
Commit
5187986
·
1 Parent(s): d19ba12

Create new file

Browse files
Files changed (1) hide show
  1. app.py +31 -0
app.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import openai
2
+ import gradio as gr
3
+ import os
4
+
5
+ #OpenAi call
6
+ def regex(texts):
7
+ openai.api_key = os.environ["Secret"]
8
+ response = openai.Completion.create(
9
+ engine="code-davinci-002",
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 regex response from model
23
+ def greet(prompt):
24
+ txt= (f'''Perfect Regex Generator \n #Prompt: {prompt}\n#Regex:\n''')
25
+ regex = 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 Regex", description="Enter any prompt and get a regex statement back! For better results, give it more context")
31
+ iface.launch()