Miguel Cardoso commited on
Commit
9eb770c
·
1 Parent(s): 6510272

some more work

Browse files
Files changed (4) hide show
  1. app.py +25 -7
  2. myreport.md +23 -0
  3. pages/selfreport.py +5 -0
  4. simplereview.md +1 -1
app.py CHANGED
@@ -25,22 +25,34 @@ api_key = st.text_input("Enter your OpenAI API Key:", type="password")
25
 
26
 
27
  def llmcall(input):
28
- simple_review = MinimalPromptParser().parse_file('simplereview.md', {'code':input})
 
 
29
 
 
30
  from openai import OpenAI
31
  client = OpenAI(api_key = api_key)
 
32
  completion = client.chat.completions.create(
33
  model="gpt-3.5-turbo",
34
- messages=simple_review
 
35
  )
36
 
37
  return completion.choices[0].message.content
38
 
39
  # Title of the app
40
  st.title('Does my code suck?')
41
-
42
  # Upload file input
43
- uploaded_file = st.file_uploader("Choose a file")
 
 
 
 
 
 
 
44
 
45
  if uploaded_file is not None:
46
  # To read file as string:
@@ -56,14 +68,20 @@ if uploaded_file is not None:
56
  # Get programming language
57
  user_input = st.text_area('Your not so good code:', value = file_content, height=500, disabled=True)
58
  else:
59
- user_input = st.text_area('Your not so good code:', height=500)
 
60
 
61
  # Button to review the input
62
  if st.button('Review'):
63
  st.divider()
64
  st.header("Uff, there you go")
65
  # Output displayed when the button is clicked
66
- st.markdown(llmcall(user_input))
67
-
 
 
 
 
 
68
 
69
 
 
25
 
26
 
27
  def llmcall(input):
28
+ if not api_key:
29
+ st.toast("Please provide your OpenAI key")
30
+ return 'Shame'
31
 
32
+ simple_review = MinimalPromptParser().parse_file('simplereview.md', {'code':input})
33
  from openai import OpenAI
34
  client = OpenAI(api_key = api_key)
35
+
36
  completion = client.chat.completions.create(
37
  model="gpt-3.5-turbo",
38
+ messages=simple_review,
39
+ temperature=0.1
40
  )
41
 
42
  return completion.choices[0].message.content
43
 
44
  # Title of the app
45
  st.title('Does my code suck?')
46
+ st.subheader("FYI we do not store any of your code. Obviously. Why would we ? It sucks.")
47
  # Upload file input
48
+
49
+ upload, text, repo = st.tabs(["File", "Copy-Paste", "Public Repo Link"])
50
+
51
+ with upload:
52
+ uploaded_file = st.file_uploader("Choose a file")
53
+
54
+ with repo:
55
+ st.text_input("Your obnoxious repo link")
56
 
57
  if uploaded_file is not None:
58
  # To read file as string:
 
68
  # Get programming language
69
  user_input = st.text_area('Your not so good code:', value = file_content, height=500, disabled=True)
70
  else:
71
+ with text:
72
+ user_input = st.text_area('Or paste here your not so good code:', height=500)
73
 
74
  # Button to review the input
75
  if st.button('Review'):
76
  st.divider()
77
  st.header("Uff, there you go")
78
  # Output displayed when the button is clicked
79
+ with st.spinner('Reading...'):
80
+ markdown, raw = st.tabs(["Markdown", "Raw"])
81
+ reviewed_coded = llmcall(user_input)
82
+ with markdown:
83
+ st.markdown(reviewed_coded)
84
+ with raw:
85
+ st.code(reviewed_coded)
86
 
87
 
myreport.md ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ## Code Review 🕵️‍♂️
2
+
3
+ Oh boy, where do I start with this code? Let's just dive right in, shall we?
4
+
5
+ ### Import Statements
6
+ - It looks like you've imported the `streamlit` library, but you're also trying to import `parser`. Is that a custom parser module you wrote, or did you mean `import os`?
7
+
8
+ ### Function Naming
9
+ - What's up with the `llmcall` function name? It sounds like a mix between a rapper's stage name and a function that needs some serious refactoring.
10
+
11
+ ### Error Handling
12
+ - Your `get_language_from_extension` function is missing error handling for unsupported file extensions. What if someone tries to upload a `.txt` file? Are we just supposed to assume it's Python? 🤔
13
+
14
+ ### API Key Security
15
+ - Storing the OpenAI API key directly in the code? Oh, the horror! Please tell me this is just for demonstration purposes and not how you actually handle sensitive information.
16
+
17
+ ### User Experience
18
+ - The snarky comments about code quality are a nice touch, but maybe tone it down a bit? We're here to help, not to crush dreams (even if the code quality is questionable).
19
+
20
+ ### Overall Impressions
21
+ - Despite the sass and questionable practices, I appreciate the effort you put into this app. Just remember, code can always be improved (especially yours 😉).
22
+
23
+ Keep coding and striving for cleaner, more secure solutions! I'll be here to roast... I mean review your code anytime. Cheers! 🚀🔥
pages/selfreport.py ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ import streamlit as st
2
+
3
+ with open('myreport.md') as content_file:
4
+ content = content_file.read()
5
+ st.markdown(content)
simplereview.md CHANGED
@@ -1,4 +1,4 @@
1
  system:
2
- You are an harsh code reviewer that enforces diligent and good code practices. You are tasked with reviewing the user code in a funny, spitefull and relevant way. Use markdown.
3
  user:
4
  {{code}}
 
1
  system:
2
+ You are an harsh code reviewer that enforces diligent and good code practices. You know it all, and the user knows nothing! You are tasked with reviewing the user code in a funny, spitefull and relevant way. Use markdown. Use puns and emojis.
3
  user:
4
  {{code}}