Spaces:
Runtime error
Runtime error
| import openai | |
| import gradio as gr | |
| # Set your OpenAI API key here | |
| api_key = "YOUR_API_KEY" | |
| # Initialize the OpenAI API client | |
| openai.api_key = api_key | |
| # Define a function to generate responses using GPT-3.5 Turbo | |
| def generate_response(prompt): | |
| response = openai.Completion.create( | |
| model="gpt-3.5-turbo", # Use GPT-3.5 Turbo engine | |
| prompt=prompt, | |
| max_tokens=50, # You can adjust this to limit the response length | |
| ) | |
| return response.choices[0].text | |
| # Create a Gradio interface | |
| iface = gr.Interface( | |
| fn=generate_response, | |
| inputs="text", | |
| outputs="text", | |
| title="Detect Prompt Category", | |
| description="Enter a prompt, and GPT-3.5 Turbo will generate a response.", | |
| ) | |
| # Start the Gradio interface | |
| iface.launch() | |