Spaces:
Runtime error
Runtime error
Commit
·
bcdfe0a
1
Parent(s):
bf7ef22
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import openai
|
| 3 |
+
|
| 4 |
+
# Set up OpenAI API key
|
| 5 |
+
openai.api_key = "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"
|
| 6 |
+
|
| 7 |
+
# Define the code generation function
|
| 8 |
+
def code_generation(message):
|
| 9 |
+
# Set the model name and parameters
|
| 10 |
+
model = "nlpxucan/wizardlm-base"
|
| 11 |
+
max_tokens = 100
|
| 12 |
+
|
| 13 |
+
# Generate code using the model
|
| 14 |
+
response = openai.Completion.create(
|
| 15 |
+
engine="text-davinci-003",
|
| 16 |
+
prompt=message,
|
| 17 |
+
max_tokens=max_tokens,
|
| 18 |
+
temperature=0.7,
|
| 19 |
+
top_p=1.0,
|
| 20 |
+
n=1,
|
| 21 |
+
stop=None,
|
| 22 |
+
frequency_penalty=0.0,
|
| 23 |
+
presence_penalty=0.0,
|
| 24 |
+
log_level="info",
|
| 25 |
+
model=model
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
return response.choices[0].text.strip()
|
| 29 |
+
|
| 30 |
+
# Create the Gradio interface
|
| 31 |
+
iface = gr.Interface(
|
| 32 |
+
fn=code_generation,
|
| 33 |
+
inputs="text",
|
| 34 |
+
outputs="text",
|
| 35 |
+
title="Code Generation with WizardLM",
|
| 36 |
+
description="Enter a message as code prompt to generate code.",
|
| 37 |
+
examples=[
|
| 38 |
+
["Create a function to calculate the factorial of a number."],
|
| 39 |
+
["Sort a list of integers in ascending order."],
|
| 40 |
+
],
|
| 41 |
+
theme="default"
|
| 42 |
+
)
|
| 43 |
+
|
| 44 |
+
# Run the Gradio interface
|
| 45 |
+
iface.launch()
|