kumar1907 commited on
Commit
8d95c8b
Β·
verified Β·
1 Parent(s): 974df6f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -58
app.py CHANGED
@@ -2,65 +2,37 @@ import streamlit as st
2
  from code_reviewer import review_code
3
  from pr_fetcher import fetch_pr_diff
4
 
5
- # -----------------------------
6
- # Page Config (must be first Streamlit command)
7
- # -----------------------------
8
- st.set_page_config(
9
- page_title="Code Review Agent",
10
- page_icon="πŸ€–",
11
- layout="wide"
12
- )
13
-
14
- # -----------------------------
15
- # App Title
16
- # -----------------------------
17
  st.title("πŸ€– Code Review Agent (Hugging Face Edition)")
18
- st.write("Fetch a Pull Request from GitHub and get **AI-powered review + improved code**")
19
 
20
- # -----------------------------
21
- # Sidebar Inputs
22
- # -----------------------------
23
- with st.sidebar:
24
- st.header("πŸ“‚ GitHub PR Details")
25
- owner = st.text_input("GitHub Repo Owner", "kumar1905")
26
- repo = st.text_input("GitHub Repo Name", "TEMPERATURE-CONVERTOR")
27
- pr_number = st.number_input("PR Number", min_value=1, value=1, step=1)
28
- token = st.text_input("GitHub Token (optional if public repo)", type="password")
29
- fetch_btn = st.button("πŸš€ Fetch & Review PR")
30
 
31
- # -----------------------------
32
- # Fetch + Review
33
- # -----------------------------
34
- if fetch_btn:
35
  with st.spinner("Fetching PR diff..."):
36
- diff = fetch_pr_diff(owner, repo, pr_number, token)
37
-
38
- if diff.startswith("Error"):
39
- st.error(diff)
40
- else:
41
- st.success("βœ… PR diff fetched successfully!")
42
- with st.expander("πŸ“„ View Raw PR Diff"):
43
- st.code(diff, language="diff")
44
-
45
- with st.spinner("Analyzing code with Hugging Face model..."):
46
- feedback, code = review_code(diff)
47
-
48
- # Feedback Section
49
- st.subheader("πŸ’‘ Review Feedback")
50
- if feedback:
51
- st.write(feedback)
52
- else:
53
- st.warning("No feedback generated.")
54
-
55
- # Improved Code Section
56
- st.subheader("✨ Suggested Improved Code")
57
- if code:
58
- st.code(code, language="python")
59
- else:
60
- st.warning("No improved code generated.")
61
-
62
- # -----------------------------
63
- # Footer
64
- # -----------------------------
65
- st.markdown("---")
66
- st.markdown("Built with ❀️ using [Streamlit](https://streamlit.io/) & [Hugging Face Transformers](https://huggingface.co/)")
 
2
  from code_reviewer import review_code
3
  from pr_fetcher import fetch_pr_diff
4
 
5
+ st.set_page_config(page_title="Code Review Agent", layout="wide")
 
 
 
 
 
 
 
 
 
 
 
6
  st.title("πŸ€– Code Review Agent (Hugging Face Edition)")
7
+ st.caption("Fetch a Pull Request from GitHub and get AI-powered review + improved code")
8
 
9
+ # Sidebar for inputs
10
+ st.sidebar.header("πŸ”— GitHub PR Details")
11
+ repo_owner = st.sidebar.text_input("GitHub Repo Owner", placeholder="e.g. openai")
12
+ repo_name = st.sidebar.text_input("GitHub Repo Name", placeholder="e.g. gpt-code-review")
13
+ pr_number = st.sidebar.number_input("PR Number", min_value=1, step=1)
14
+ github_token = st.sidebar.text_input("GitHub Token (optional if public repo)", type="password")
 
 
 
 
15
 
16
+ if st.sidebar.button("πŸš€ Fetch & Review PR"):
 
 
 
17
  with st.spinner("Fetching PR diff..."):
18
+ diff_text = fetch_pr_diff(repo_owner, repo_name, pr_number, github_token)
19
+
20
+ if diff_text.startswith("Error"):
21
+ st.error(diff_text)
22
+ else:
23
+ st.success("βœ… PR diff fetched successfully!")
24
+
25
+ # Display the diff for reference
26
+ with st.expander("πŸ” View Raw PR Diff"):
27
+ st.code(diff_text, language="diff")
28
+
29
+ # Review with LLM
30
+ with st.spinner("Analyzing code with Hugging Face model..."):
31
+ feedback, improved_code = review_code(diff_text)
32
+
33
+ # Show results
34
+ st.subheader("πŸ’‘ Review Feedback")
35
+ st.markdown(feedback)
36
+
37
+ st.subheader("✨ Suggested Improved Code")
38
+ st.code(improved_code, language="python")