CoolFace
Apppublic

Gradio-Blocks/Codex_OpenAI

sourceHugging Faceapache-2.0updated 4y agoView on Hugging Face
57likes
app.py61 linesDownload Raw Back to root
1import openai2import numpy as np3import os4import json5import gradio as gr6 7openai.api_key = os.environ["api_key"]8engine = "code-davinci-002"9 10 11def happytt(temperature,max_tokens,text,stop):12  try:13    s = json.loads(stop)14    response = openai.Completion.create(15      engine=engine,16      prompt=text,17      temperature=temperature,18      max_tokens=max_tokens,19      top_p=1,20      frequency_penalty=0,21      presence_penalty=0,22      stop=s23    )24  except json.JSONDecodeError:25    response = openai.Completion.create(26      engine=engine,27      prompt=text,28      temperature=temperature,29      max_tokens=max_tokens,30      top_p=1,31      frequency_penalty=0,32      presence_penalty=033    )34 35  return response.choices[0].text36 37 38title = "OpenAI Codex"39description = '''OpenAI Codex is an artificial intelligence model developed by OpenAI. 40It parses natural language and generates code in response. 41It is used to power GitHub Copilot, a programming autocompletion 42tool developed for  Code generation.43 44Try following prompts and tweak temperatures  in following links -45 46https://www.pragnakalp.com/experimenting-with-openai-codex/47 48https://betterprogramming.pub/i-beta-tested-openais-codex-and-the-results-are-spooky-good-e282a1874c7949 50https://beta.openai.com/examples?category=code51 52Built by  [mohammed arsalan](https://www.linkedin.com/in/sallu-mandya/)'''53 54 55iface = gr.Interface( happytt,[ gr.Slider(0, 1, step=0.1),gr.Slider(150, 4000, step=1),56                               gr.Textbox(type='str',   57                                                 label="input prompt"),58                               gr.Textbox(type='str',   59                                                 label="list of tokens, when to finish generating",60                                                 placeholder='["<code>", "import"]')],"text", title = title, description = description )61iface.launch(debug=True)