|
1 | 1 | import streamlit as st |
2 | 2 | import os |
3 | 3 | import time |
| 4 | +import hashlib |
4 | 5 | from src.graph import create_ase_graph |
5 | 6 | from src.tools.github_tools import GitHubTool |
6 | 7 | from dotenv import load_dotenv |
7 | 8 |
|
8 | | -# Load env but also allow manual override in sidebar |
| 9 | +# Load local .env (ignored if deployed on Streamlit Cloud) |
9 | 10 | load_dotenv() |
10 | 11 |
|
11 | 12 | st.set_page_config( |
|
52 | 53 | st.image("Ghost_coder_logo.png", width=500) |
53 | 54 | st.title("Settings") |
54 | 55 |
|
55 | | - st.markdown("### API Keys") |
56 | | - gh_token = st.text_input("GitHub Token", value=os.getenv("GITHUB_TOKEN", ""), type="password") |
57 | | - groq_key = st.text_input("Groq API Key", value=os.getenv("GROQ_API_KEY", ""), type="password") |
| 56 | + st.markdown("### Authentication") |
| 57 | + app_password = st.text_input("App Password", type="password", help="Enter the password to use this app.") |
58 | 58 |
|
59 | | - if gh_token: os.environ["GITHUB_TOKEN"] = gh_token |
60 | | - if groq_key: os.environ["GROQ_API_KEY"] = groq_key |
| 59 | + # Load keys from Streamlit Secrets or .env |
| 60 | + gh_token = "" |
| 61 | + groq_key = "" |
| 62 | + expected_password = "demo" # Fallback password if not set |
| 63 | + |
| 64 | + try: |
| 65 | + gh_token = st.secrets.get("GITHUB_TOKEN") or os.getenv("GITHUB_TOKEN", "") |
| 66 | + groq_key = st.secrets.get("GROQ_API_KEY") or os.getenv("GROQ_API_KEY", "") |
| 67 | + expected_password = st.secrets.get("APP_PASSWORD") or os.getenv("APP_PASSWORD", "demo") |
| 68 | + except Exception: |
| 69 | + gh_token = os.getenv("GITHUB_TOKEN", "") |
| 70 | + groq_key = os.getenv("GROQ_API_KEY", "") |
| 71 | + expected_password = os.getenv("APP_PASSWORD", "demo") |
61 | 72 |
|
62 | 73 |
|
63 | 74 | # --- Main UI --- |
|
87 | 98 | issue_url = st.text_input("Issue URL", placeholder="https://github.com/owner/repo/issues/123") |
88 | 99 |
|
89 | 100 | if st.button("Execute Autonomous Fix"): |
90 | | - if not issue_url: |
| 101 | + if app_password != expected_password: |
| 102 | + st.error("Incorrect password.") |
| 103 | + elif not issue_url: |
91 | 104 | st.warning("Please provide a GitHub Issue URL.") |
92 | | - elif not os.getenv("GITHUB_TOKEN") or not os.getenv("GROQ_API_KEY"): |
93 | | - st.error("Missing API keys. Please set them in the sidebar or .env file.") |
| 105 | + elif not gh_token or not groq_key: |
| 106 | + st.error("Missing API keys in Streamlit secrets or .env file.") |
94 | 107 | else: |
95 | | - gh_tool = GitHubTool() |
| 108 | + gh_tool = GitHubTool(token=gh_token) |
96 | 109 |
|
97 | 110 | with st.status("Initializing Environment...", expanded=True) as status: |
98 | 111 | st.write("🔍 Fetching issue metadata...") |
|
104 | 117 |
|
105 | 118 | st.write(f"**Targeting:** {issue_info['title']}") |
106 | 119 |
|
107 | | - workspace_dir = os.path.abspath("./workspace_clones/target_repo") |
| 120 | + session_id = hashlib.md5(issue_url.encode()).hexdigest()[:8] |
| 121 | + workspace_dir = os.path.abspath(f"./workspace_clones/target_repo_{session_id}") |
108 | 122 | st.write("📂 Cloning repository to workspace...") |
109 | 123 | if not gh_tool.clone_repository(issue_url, workspace_dir): |
110 | 124 | st.error("Failed to clone repository. Workspace may be locked.") |
|
117 | 131 | "issue_url": issue_url, |
118 | 132 | "issue_description": f"{issue_info['title']}\n\n{issue_info['body']}", |
119 | 133 | "repo_path": workspace_dir, |
| 134 | + "github_token": gh_token, |
| 135 | + "groq_api_key": groq_key, |
120 | 136 | "files_to_modify": [], |
121 | 137 | "research_summary": "", |
122 | 138 | "updated_code": {}, |
|
179 | 195 | st.header("🚀 Deployment Pipeline (Human-in-the-Loop)") |
180 | 196 |
|
181 | 197 | final_state = st.session_state.final_state |
182 | | - gh_tool = GitHubTool() |
| 198 | + gh_tool = GitHubTool(token=final_state["github_token"]) |
183 | 199 | repo_path = final_state["repo_path"] |
184 | 200 | issue_url = final_state["issue_url"] |
185 | 201 | files_to_update = list(final_state["updated_code"].keys()) |
|
0 commit comments