Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import openai
|
| 2 |
+
import gradio as gr
|
| 3 |
+
|
| 4 |
+
# Set up OpenAI API key
|
| 5 |
+
openai.api_key = 'your_openai_api_key_here' # Replace with your OpenAI API key
|
| 6 |
+
|
| 7 |
+
# Function to generate code based on user input
|
| 8 |
+
def generate_code(input_text):
|
| 9 |
+
try:
|
| 10 |
+
# Use GPT-3 to generate code
|
| 11 |
+
response = openai.Completion.create(
|
| 12 |
+
engine="text-davinci-003",
|
| 13 |
+
prompt=f"Generate a code based on the following request: {input_text}",
|
| 14 |
+
max_tokens=150,
|
| 15 |
+
n=1,
|
| 16 |
+
stop=None,
|
| 17 |
+
temperature=0.7
|
| 18 |
+
)
|
| 19 |
+
# Extract the response text
|
| 20 |
+
code = response.choices[0].text.strip()
|
| 21 |
+
return code
|
| 22 |
+
except Exception as e:
|
| 23 |
+
return f"Error: {str(e)}"
|
| 24 |
+
|
| 25 |
+
# Gradio Interface setup
|
| 26 |
+
iface = gr.Interface(
|
| 27 |
+
fn=generate_code, # Function to call
|
| 28 |
+
inputs="text", # User input type (text input box)
|
| 29 |
+
outputs="text", # Output type (text box for the generated code)
|
| 30 |
+
title="HandyAI - Your All Purpose AI", # Title of the app
|
| 31 |
+
description="HandyAI generates code based on your request. Simply describe what you want, and it will generate code for you.", # Description
|
| 32 |
+
theme="compact", # Interface theme (compact, default, etc.)
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
# Launch the interface
|
| 36 |
+
iface.launch()
|