Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import os
|
| 3 |
+
import openai
|
| 4 |
+
|
| 5 |
+
openai.api_key = "API"
|
| 6 |
+
|
| 7 |
+
demo = gr.Blocks()
|
| 8 |
+
|
| 9 |
+
#'spaces/Gradio-Blocks/Codex_OpenAI' did not work due to paramerts error
|
| 10 |
+
#'huggingface/facebook/incoder-6B' inference error
|
| 11 |
+
|
| 12 |
+
name_list = ['huggingface/lvwerra/codeparrot','huggingface/facebook/incoder-1B', 'huggingface/Salesforce/codegen-2B-mono']
|
| 13 |
+
|
| 14 |
+
open_ai_name = ['openai/code-davinci-002', 'openai/code-cushman-001']
|
| 15 |
+
|
| 16 |
+
def generate_code_os(text):
|
| 17 |
+
interfaces = [gr.Interface.load(name) for name in name_list]
|
| 18 |
+
return [interface(text) for interface in interfaces]
|
| 19 |
+
|
| 20 |
+
def generate_code_cs_1(text):
|
| 21 |
+
response = openai.Completion.create(
|
| 22 |
+
engine="code-davinci-002",
|
| 23 |
+
prompt="",
|
| 24 |
+
temperature=0,
|
| 25 |
+
max_tokens=256,
|
| 26 |
+
top_p=1,
|
| 27 |
+
frequency_penalty=0,
|
| 28 |
+
presence_penalty=0
|
| 29 |
+
).choices[0].text
|
| 30 |
+
response_2 = generate_code_cs_2(text)
|
| 31 |
+
return [response, response_2]
|
| 32 |
+
|
| 33 |
+
def generate_code_cs_2(text):
|
| 34 |
+
response_2 = openai.Completion.create(
|
| 35 |
+
engine="code-cushman-001",
|
| 36 |
+
prompt="",
|
| 37 |
+
temperature=0,
|
| 38 |
+
max_tokens=256,
|
| 39 |
+
top_p=1,
|
| 40 |
+
frequency_penalty=0,
|
| 41 |
+
presence_penalty=0
|
| 42 |
+
).choices[0].text
|
| 43 |
+
return response_2
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
with gr.Blocks() as demo:
|
| 47 |
+
gr.Markdown("# Compare OpenAI and HuggingFace Code Generators")
|
| 48 |
+
with gr.Box():
|
| 49 |
+
with gr.Row():
|
| 50 |
+
with gr.Column():
|
| 51 |
+
input_text = gr.Textbox(label = "Write your code here", lines=4)
|
| 52 |
+
with gr.Row():
|
| 53 |
+
btn = gr.Button("Open-Source models Generate code brrr ...")
|
| 54 |
+
btn2 = gr.Button("OpenAI models Generate code brrr ...")
|
| 55 |
+
|
| 56 |
+
with gr.Column():
|
| 57 |
+
gr.Markdown("Let’s Compare code generators ")
|
| 58 |
+
btn2.click(generate_code_cs_1, inputs = input_text, outputs = [gr.Textbox(label=open_ai_name[_], lines=4) for _ in range(len(open_ai_name))])
|
| 59 |
+
with gr.Column():
|
| 60 |
+
btn.click(generate_code_os, inputs = input_text, outputs = [gr.Textbox(label=name_list[_], lines=4) for _ in range(len(name_list))])
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
demo.launch(debug=True)
|