|
import os |
|
import openai |
|
import gradio as gr |
|
|
|
openai.ChatCompletion.create( |
|
model="gpt-3.5-turbo0301", |
|
|
|
|
|
openai.api_key = os.environ.get("OPENAI_API_KEY") |
|
|
|
|
|
model = "gpt-3.5-turbo-0301" |
|
|
|
|
|
def generate_response(prompt): |
|
try: |
|
response = openai.Completion.create( |
|
engine=model, |
|
prompt=prompt, |
|
max_tokens=1024, |
|
n=1, |
|
stop=None, |
|
temperature=0.7, |
|
) |
|
return response.choices[0].text.strip() |
|
except Exception as e: |
|
return f"Error: {e}" |
|
|
|
|
|
input_text = gr.inputs.Textbox(label="Enter your message:") |
|
output_text = gr.outputs.Textbox(label="AI response:") |
|
|
|
|
|
gradio_app = gr.Interface( |
|
fn=generate_response, |
|
inputs=input_text, |
|
outputs=output_text, |
|
title="GPT-3.5 Turbo Chatbot", |
|
description="Enter a message and get a response from an AI chatbot powered by GPT-3.5 Turbo.", |
|
theme="compact", |
|
) |
|
|
|
|
|
gradio_app.launch(share=True) |
|
|