File size: 915 Bytes
9419609
48e1709
9419609
 
 
 
48e1709
86d8051
7e628b7
9419609
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48e1709
86d8051
 
 
48e1709
9f8507b
 
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
import os
import gradio as gr
import openai

# Set up OpenAI API
openai.api_key = os.getenv("OPENAI_API_KEY")

def chat_with_gpt(input_text):
    model_engine = "text-davinci-002" # Choose the appropriate model engine.
    prompt = f"{input_text} (AI):"

    response = openai.Completion.create(
        engine=model_engine,
        prompt=prompt,
        max_tokens=100,
        n=1,
        stop=None,
        temperature=0.8,
        top_p=1,
        frequency_penalty=0,
        presence_penalty=0
    )

    generated_text = response.choices[0].text.strip()
    return generated_text

# Gradio user interface
input_text = gr.inputs.Textbox(lines=5, label="Your question about AI:")
output_text = gr.outputs.Textbox(label="ChatGPT Response:")

iface = gr.Interface(fn=chat_with_gpt, inputs=input_text, outputs=output_text, title="Chat with ChatGPT", description="Ask ChatGPT questions about AI.")
iface.launch()