Spaces:
Sleeping
Sleeping
Create app.py
#1
by
Aniquel
- opened
app.py
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import openai
|
3 |
+
import os
|
4 |
+
|
5 |
+
openai.api_key = os.getenv("OPENAI_API_KEY")
|
6 |
+
|
7 |
+
MODEL = gpt-3.5-turbo
|
8 |
+
|
9 |
+
def generate_response(text):
|
10 |
+
prompt = f"Code generation:\n\n```python\n{text}\n```"
|
11 |
+
response = openai.Completion.create(
|
12 |
+
model=MODEL,
|
13 |
+
prompt=prompt,
|
14 |
+
max_tokens=3000,
|
15 |
+
n=1,
|
16 |
+
stop=None,
|
17 |
+
temperature=0.2,
|
18 |
+
)
|
19 |
+
message = response.choices[0].text.strip()
|
20 |
+
return message
|
21 |
+
|
22 |
+
iface = gr.Interface(
|
23 |
+
fn=generate_response,
|
24 |
+
inputs=gr.inputs.Textbox(label="Enter your code here"),
|
25 |
+
outputs=gr.outputs.Textbox(label="Chatbot's response"),
|
26 |
+
title="WizApp Code Generation",
|
27 |
+
description="Use AI to generate code based on your input",
|
28 |
+
theme="default"
|
29 |
+
)
|
30 |
+
|
31 |
+
if __name__ == "__main__":
|
32 |
+
iface.launch()
|