Spaces:
Runtime error
Runtime error
| import os | |
| import openai | |
| import gradio as gr | |
| from dotenv import load_dotenv | |
| load_dotenv() | |
| key = os.getenv("OPENAI_API_KEY") | |
| if not key: | |
| raise ValueError() | |
| openai.api_key = key | |
| def tutor(input): | |
| if not input.strip(): | |
| return "Valid only" | |
| response = openai.ChatCompletion.create( | |
| model= "gpt-4o-mini", | |
| messages =[ | |
| { | |
| "role" : "system", | |
| "content" : "You are a PhD level Python Professor who answers questions about Python even a middle schooler can understand." | |
| "WHen answering, you give atleast two code examples along with it. Showing the output with the code is a must. you should tell the Exceptions and errors that may occur " | |
| "while coding pertaining to the question. " | |
| } | |
| { | |
| "role" : "user", | |
| "content" : input | |
| } | |
| ], | |
| temperature = 0.03, | |
| max_tokens=2000, | |
| top_p=0.1, | |
| frequency_penalty=0.1, | |
| presence_penalty=0.95 | |
| ) | |
| return response ["choice"][0]["message"]["content"] | |
| chatbot_ui = gr.Interface( | |
| fn = tutor, | |
| inputs= gr.Textbox(lines=3, placeholder = "Ask"), | |
| outputs= gr.Textbox(), | |
| title="Python Tutor Bot", | |
| description ="Ask away" | |
| ) | |
| if __name__ == "__main__": | |
| chatbot_ui.launch(share=True) |