File size: 982 Bytes
6c7eead
95444d1
 
6c7eead
ef39f9e
6c7eead
94615f2
6c7eead
e5b5bad
ef39f9e
14e8d10
ef39f9e
 
 
 
e5b5bad
ef39f9e
e5b5bad
 
6c7eead
 
 
 
 
 
 
95444d1
 
6c7eead
 
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
import openai
import gradio as gr

# Set up OpenAI API key
openai_api_key = "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"

# Define a function to call the OpenAI API
def chatbot(input_text):
    try:
        response = openai.ChatCompletion.create(
            model="gpt-3.5-turbo",  # You can change this to GPT-4 or others
            messages=[
                {"role": "system", "content": "You are a helpful assistant."},
                {"role": "user", "content": input_text},
            ]
        )
        return response['choices'][0]['message']['content'].strip()
    except Exception as e:
        return f"Error: {str(e)}"

# Create the Gradio interface
iface = gr.Interface(
    fn=chatbot,
    inputs=gr.Textbox(lines=2, placeholder="Type your message here..."),
    outputs=gr.Textbox(),
    live=True
)

# Launch the interface
iface.launch()