kodamkarthik281 commited on
Commit
6c2c800
·
verified ·
1 Parent(s): 02ef991

Delete main.py

Browse files
Files changed (1) hide show
  1. main.py +0 -54
main.py DELETED
@@ -1,54 +0,0 @@
1
- import streamlit as st
2
- import google.generativeai as genai
3
-
4
- st.title("AI Code Reviewer ")
5
-
6
- try:
7
- with open("API_key.txt", "r") as f:
8
- api_key = f.read().strip()
9
- genai.configure(api_key=api_key)
10
- model = genai.GenerativeModel(model_name="gemini-2.0-flash-001")
11
- except Exception as e:
12
- st.error("API Key Error! Please check your API key file.")
13
- st.stop()
14
-
15
- sys_prompt = """You are an AI Code Reviewer. Your task is to analyze submitted code in any programming language.
16
- If the code contains errors or bugs:
17
- 1. Explain the errors briefly and why they occurred.
18
- 2. Provide the corrected version in a copyable format.
19
-
20
- If the code has no errors:
21
- - Explain what the code does in short.
22
-
23
- If the question is not related to programming or data science, reply humorously that you are a code reviewer. Keep responses concise and focused."""
24
-
25
- if "history" not in st.session_state:
26
- st.session_state.history = []
27
-
28
- user_query = st.text_area("Submit your code for review:", height=150, key="user_input")
29
-
30
- if st.button("Submit") and user_query.strip():
31
- with st.spinner("Reviewing your code... "):
32
- try:
33
- response = model.generate_content(f"{sys_prompt}\n\nUser: {user_query}")
34
- ai_response = response.text.strip() if response.text else " Error: No response received."
35
-
36
- st.session_state.history.append({"query": user_query, "response": ai_response})
37
-
38
- st.subheader("Review Result:")
39
- st.write(ai_response)
40
-
41
- except Exception as e:
42
- st.error(f"An error occurred: {e}")
43
-
44
- st.sidebar.title("Review History")
45
- if st.session_state.history:
46
- queries = [f"Query {i+1}" for i in range(len(st.session_state.history))]
47
- selected_query = st.sidebar.selectbox("Select a past query:", queries, index=len(queries)-1)
48
-
49
- if selected_query:
50
- idx = queries.index(selected_query)
51
- st.sidebar.subheader("Selected Review Result:")
52
- st.sidebar.write(st.session_state.history[idx]["response"])
53
- else:
54
- st.sidebar.write("No queries yet. Submit your code above!")