Mpavan45 commited on
Commit
5ff30f6
Β·
verified Β·
1 Parent(s): b879464

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -17
app.py CHANGED
@@ -16,28 +16,54 @@ def animated_text(text, speed=0.05):
16
  animated_text("Welcome to GenAI App - AI Code Reviewer!", speed=0.1)
17
 
18
  import google.generativeai as genai
19
- st.header('πŸš€ AI-Powered Code Debugging πŸ”: ')
20
 
21
- st.subheader('🐞 Buggy Code::')
 
22
 
23
- # Text Area for User Input
24
- code = st.text_area("Enter your code here:", height=200)
25
 
26
- # Display the Code with Syntax Highlighting
27
- if code:
28
- st.code(code, language="python") # Adjust language as needed
29
 
30
- # Copy Code Button
31
- st.markdown(
32
- f"""
33
- <button onclick="navigator.clipboard.writeText(`{code}`)">Debug Code</button>
34
- """,
35
- unsafe_allow_html=True
36
- )
 
 
 
 
 
 
 
 
 
 
37
 
 
 
 
 
 
 
 
38
 
39
- st.subheader('πŸ” Bug Found in:')
 
 
40
 
41
- st.subheader('βœ… Fixed Code:')
 
 
 
 
 
 
42
 
43
- st.subheader('πŸ’‘ Suggestion:')
 
 
 
16
  animated_text("Welcome to GenAI App - AI Code Reviewer!", speed=0.1)
17
 
18
  import google.generativeai as genai
 
19
 
20
+ # Set up Google Gemini API Key
21
+ genai.configure(api_key=st.secrets["AIzaSyBm0GOvYox4OyRG1WFOK7FT5fnNCHfubns"])
22
 
23
+ # Streamlit App Title
24
+ st.title("πŸ€– AI-Powered Code Debugging")
25
 
26
+ # Text Area for User Input (Buggy Code)
27
+ buggy_code = st.text_area("🐞 Enter your buggy code here:", height=200)
 
28
 
29
+ # Function to Debug Code Using Gemini AI
30
+ def debug_code_with_gemini(code):
31
+ prompt = f"Debug the following code and provide the corrected version:\n\n{code}"
32
+
33
+ model = genai.GenerativeModel("models/gemini-2.0-flash")
34
+ response = model.generate_content(prompt)
35
+
36
+ return response.text if response.text else "⚠️ Error in AI response."
37
+
38
+ # Function to Generate Code Improvement Suggestions
39
+ def get_suggestions_with_gemini(code):
40
+ prompt = f"Suggest improvements for the following code, focusing on best practices, performance optimization, and readability:\n\n{code}"
41
+
42
+ model = genai.GenerativeModel("gemini-pro")
43
+ response = model.generate_content(prompt)
44
+
45
+ return response.text if response.text else "⚠️ No suggestions available."
46
 
47
+ # Process Code When Input is Given
48
+ if buggy_code:
49
+ with st.spinner("πŸ› οΈ Debugging your code..."):
50
+ fixed_code = debug_code_with_gemini(buggy_code)
51
+
52
+ with st.spinner("πŸ” Generating suggestions..."):
53
+ suggestions = get_suggestions_with_gemini(fixed_code)
54
 
55
+ # Display Fixed Code
56
+ st.subheader("βœ… Fixed Code:")
57
+ st.code(fixed_code, language="python") # Adjust language if needed
58
 
59
+ # Copy Button for Fixed Code
60
+ st.download_button(
61
+ label="πŸ“‹ Copy Fixed Code",
62
+ data=fixed_code,
63
+ file_name="fixed_code.py",
64
+ mime="text/plain"
65
+ )
66
 
67
+ # Display AI-Generated Suggestions
68
+ st.subheader("πŸ’‘ Suggestions for Improvement:")
69
+ st.write(suggestions)