WIzardLLM-X / app.py
typesdigital's picture
Update app.py
a95c496
import gradio as gr
import openai
# Set up OpenAI API key
openai.api_key = "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"
# Define the code generation function
def code_generation(code):
# Set the model name and parameters
model = "openai-codex"
max_tokens = 100
# Generate code suggestions using the model
response = openai.Completion.create(
engine="davinci-codex",
prompt=code,
max_tokens=max_tokens,
temperature=0.7,
top_p=1.0,
n=1,
stop=None,
frequency_penalty=0.0,
presence_penalty=0.0,
log_level="info",
model=model
)
return response.choices[0].text.strip()
# Create the Gradio interface
iface = gr.Interface(
fn=code_generation,
inputs="text",
outputs="text",
title="Code Writing and Debugging",
description="Write code and get code suggestions.",
examples=[
["for i in range(10):", "\tprint(i)"],
["def factorial(n):", "\tif n == 0:", "\t\treturn 1", "\telse:", "\t\treturn n * factorial(n-1)"]
],
allow_flagging=False,
layout="vertical",
theme="compact",
live=True,
)
# Run the Gradio interface
iface.launch()