Spaces:
Runtime error
Runtime error
Download app.py from Xakiy/python-tutor-bot: direct link, hf CLI and curl.
- Browser
- Download file 1.36 kB
-
https://huggingface.co/spaces/Xakiy/python-tutor-bot/resolve/bdf8a07bc81a371fb4ddb88933d032c691dcccdd/app.py
- Command line
-
hf download hf://spaces/Xakiy/python-tutor-bot@bdf8a07bc81a371fb4ddb88933d032c691dcccdd/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Xakiy/python-tutor-bot/resolve/bdf8a07bc81a371fb4ddb88933d032c691dcccdd/app.py
1.36 kB
| 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) |