Spaces:
Runtime error
Runtime error
| from transformers import pipeline, Conversation | |
| import gradio as gr | |
| import os | |
| from getpass import getpass | |
| message_list = [] | |
| response_list = [] | |
| def YourCoder_chatbot(message, history): | |
| python_code_examples = f""" | |
| --------------------- | |
| Example 1: Code Snippet | |
| def calculate_average(numbers): | |
| total = 0 | |
| for number in numbers: | |
| total += number | |
| average = total / len(numbers) | |
| return average | |
| Code Review: Consider using the sum() function to calculate the total sum of the numbers | |
| instead of manually iterating over the list. | |
| This would make the code more concise and efficient. | |
| --------------------- | |
| Example 2: Code Snippet | |
| def find_largest_number(numbers): | |
| largest_number = numbers[0] | |
| for number in numbers: | |
| if number > largest_number: | |
| largest_number = number | |
| return largest_number | |
| Code Review: Refactor the code using the max() function to find the largest number in the list. | |
| This would simplify the code and improve its readability. | |
| --------------------- | |
| """ | |
| prompt = f""" | |
| I will provide you with code snippets, | |
| and you will review them for potential issues and suggest improvements. | |
| Please focus on providing concise and actionable feedback, highlighting areas | |
| that could benefit from refactoring, optimization, or bug fixes. | |
| Your feedback should be constructive and aim to enhance the overall quality and maintainability of the code. | |
| Please avoid providing explanations for your suggestions unless specifically requested. Instead, focus on clearly identifying areas for improvement and suggesting alternative approaches or solutions. | |
| Few good examples of Python code output between #### separator: | |
| #### | |
| {python_code_examples} | |
| #### | |
| Code Snippet is shared below, delimited with triple backticks: | |
| ``` | |
| {message} | |
| ``` | |
| """ | |
| response = gr.model | |
| conversation = chatbot(prompt) | |
| return conversation[0]['generated_text'] | |
| chatbot = gr.ChatInterface(YourCoder_chatbot, title="YourCoder Chatbot", description="Enter piece of code to generate a code review!") | |
| chatbot.launch() |