import json import requests import gradio as gr API_KEY = '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' API_ENDPOINT = 'https://api.openai.com/v1/completions' def generate_response(prompt): headers = { 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + API_KEY } data = { 'model': 'text-davinci-003', 'prompt': prompt, 'temperature': 0, 'max_tokens': 2000, 'top_p': 1, 'frequency_penalty': 0.0, 'presence_penalty': 0.0 } response = requests.post(API_ENDPOINT, headers=headers, data=json.dumps(data)) response_data = json.loads(response.text) return response_data['choices'][0]['text'] def chatbot_interface(user_input): # Check if the user input contains the word "school" if 'school' in user_input.lower(): response = generate_response(user_input) else: response = "Please provide a query related to schools." return response inputs = gr.inputs.Textbox(label="User Input") output = gr.outputs.Textbox(label="Bot Response") interface_style = gr.Interface( fn=chatbot_interface, inputs=inputs, outputs=output, title="Smart School Finder General Chatbot", description="Type a message to chat with the bot.", css=".input_area { background-color: blue; } .output_area { background-color: blue; } .output_text { color: white; }" ) interface_style.launch()