Yashnik commited on
Commit
3a60826
·
verified ·
1 Parent(s): 75a4dce

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +63 -59
app.py CHANGED
@@ -1,61 +1,65 @@
1
- from transformers import pipeline, Conversation
2
- import gradio as gr
3
- import os
4
- from getpass import getpass
5
-
6
- model = os.getenv('bigcode/starcoder')
7
-
8
- chatbot = pipeline(task="text-generation")
9
-
10
- message_list = []
11
- response_list = []
12
-
13
- def YourCoder_chatbot(message, history):
14
-
15
- python_code_examples = f"""
16
- ---------------------
17
- Example 1: Code Snippet
18
- def calculate_average(numbers):
19
- total = 0
20
- for number in numbers:
21
- total += number
22
- average = total / len(numbers)
23
- return average
24
- Code Review: Consider using the sum() function to calculate the total sum of the numbers
25
- instead of manually iterating over the list.
26
- This would make the code more concise and efficient.
27
- ---------------------
28
- Example 2: Code Snippet
29
- def find_largest_number(numbers):
30
- largest_number = numbers[0]
31
- for number in numbers:
32
- if number > largest_number:
33
- largest_number = number
34
- return largest_number
35
- Code Review: Refactor the code using the max() function to find the largest number in the list.
36
- This would simplify the code and improve its readability.
37
- ---------------------
38
- """
39
-
40
- prompt = f"""
41
- I will provide you with code snippets,
42
- and you will review them for potential issues and suggest improvements.
43
- Please focus on providing concise and actionable feedback, highlighting areas
44
- that could benefit from refactoring, optimization, or bug fixes.
45
- Your feedback should be constructive and aim to enhance the overall quality and maintainability of the code.
46
- Please avoid providing explanations for your suggestions unless specifically requested. Instead, focus on clearly identifying areas for improvement and suggesting alternative approaches or solutions.
47
- Few good examples of Python code output between #### separator:
48
- ####
49
- {python_code_examples}
50
- ####
51
- Code Snippet is shared below, delimited with triple backticks:
52
- ```
53
- {message}
54
- ```
55
- """
56
 
57
- conversation = chatbot(prompt)
58
- return conversation[0]['generated_text']
 
 
 
 
 
59
 
60
- chatbot = gr.ChatInterface(YourCoder_chatbot, title="YourCoder Chatbot", description="Enter piece of code to generate a code review!")
61
- chatbot.launch()
 
1
+ # from transformers import pipeline, Conversation
2
+ # import gradio as gr
3
+ # import os
4
+ # from getpass import getpass
5
+
6
+ # model = os.getenv('bigcode/starcoder')
7
+
8
+ # chatbot = pipeline(task="text-generation")
9
+
10
+ # message_list = []
11
+ # response_list = []
12
+
13
+ # def YourCoder_chatbot(message, history):
14
+
15
+ # python_code_examples = f"""
16
+ # ---------------------
17
+ # Example 1: Code Snippet
18
+ # def calculate_average(numbers):
19
+ # total = 0
20
+ # for number in numbers:
21
+ # total += number
22
+ # average = total / len(numbers)
23
+ # return average
24
+ # Code Review: Consider using the sum() function to calculate the total sum of the numbers
25
+ # instead of manually iterating over the list.
26
+ # This would make the code more concise and efficient.
27
+ # ---------------------
28
+ # Example 2: Code Snippet
29
+ # def find_largest_number(numbers):
30
+ # largest_number = numbers[0]
31
+ # for number in numbers:
32
+ # if number > largest_number:
33
+ # largest_number = number
34
+ # return largest_number
35
+ # Code Review: Refactor the code using the max() function to find the largest number in the list.
36
+ # This would simplify the code and improve its readability.
37
+ # ---------------------
38
+ # """
39
+
40
+ # prompt = f"""
41
+ # I will provide you with code snippets,
42
+ # and you will review them for potential issues and suggest improvements.
43
+ # Please focus on providing concise and actionable feedback, highlighting areas
44
+ # that could benefit from refactoring, optimization, or bug fixes.
45
+ # Your feedback should be constructive and aim to enhance the overall quality and maintainability of the code.
46
+ # Please avoid providing explanations for your suggestions unless specifically requested. Instead, focus on clearly identifying areas for improvement and suggesting alternative approaches or solutions.
47
+ # Few good examples of Python code output between #### separator:
48
+ # ####
49
+ # {python_code_examples}
50
+ # ####
51
+ # Code Snippet is shared below, delimited with triple backticks:
52
+ # ```
53
+ # {message}
54
+ # ```
55
+ # """
56
 
57
+ # conversation = chatbot(prompt)
58
+ # return conversation[0]['generated_text']
59
+
60
+ # chatbot = gr.ChatInterface(YourCoder_chatbot, title="YourCoder Chatbot", description="Enter piece of code to generate a code review!")
61
+ # chatbot.launch()
62
+
63
+ import gradio as gr
64
 
65
+ gr.load("models/bigcode/starcoder").launch()