File size: 1,141 Bytes
6caa426
8caf31f
 
ff6a62e
8caf31f
 
ff6a62e
8caf31f
 
ff6a62e
8caf31f
 
ff6a62e
8caf31f
 
 
 
 
 
 
 
 
 
ff6a62e
8caf31f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import os
import openai
import gradio as gr

openai.ChatCompletion.create(
  model="gpt-3.5-turbo0301",
    
# Set OpenAI API key from environment variable
openai.api_key = os.environ.get("OPENAI_API_KEY")

# Define GPT-3.5 Turbo model
model = "gpt-3.5-turbo-0301"

# Define function for generating responses
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}"

# Define input and output interfaces
input_text = gr.inputs.Textbox(label="Enter your message:")
output_text = gr.outputs.Textbox(label="AI response:")

# Define Gradio app
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",
)

# Launch Gradio app
gradio_app.launch(share=True)