Spaces:
Sleeping
Sleeping
V2
Browse filesI have added two button.
1. Copy
2. Download
app.py
CHANGED
|
@@ -35,7 +35,7 @@ HTML_TEMPLATE = """
|
|
| 35 |
color: #1c1e21;
|
| 36 |
margin: 0;
|
| 37 |
display: flex;
|
| 38 |
-
flex-direction: column;
|
| 39 |
justify-content: center;
|
| 40 |
align-items: center;
|
| 41 |
min-height: 100vh;
|
|
@@ -62,22 +62,20 @@ HTML_TEMPLATE = """
|
|
| 62 |
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
|
| 63 |
#result-container { display: none; margin-top: 20px; }
|
| 64 |
#result { margin-top: 10px; padding: 20px; background-color: #f7f7f7; border: 1px solid #dddfe2; border-radius: 6px; text-align: left; white-space: pre-wrap; font-family: 'Courier New', Courier, monospace; max-height: 400px; overflow-y: auto; word-wrap: break-word; }
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
color: #8a8d91;
|
| 72 |
-
}
|
| 73 |
-
footer a {
|
| 74 |
-
color: #1877f2;
|
| 75 |
-
text-decoration: none;
|
| 76 |
font-weight: 600;
|
|
|
|
|
|
|
| 77 |
}
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
}
|
|
|
|
| 81 |
</style>
|
| 82 |
</head>
|
| 83 |
<body>
|
|
@@ -86,28 +84,43 @@ HTML_TEMPLATE = """
|
|
| 86 |
<p>Enter a public GitHub repository URL and let a true AI agent analyze the code and generate a README for you.</p>
|
| 87 |
<form id="repo-form"><div class="input-group"><input type="url" id="repo-url" placeholder="e.g., https://github.com/user/project" required><button type="submit">Generate</button></div></form>
|
| 88 |
<div class="loader" id="loader"></div>
|
| 89 |
-
<div id="result-container"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
</div>
|
| 91 |
|
| 92 |
-
<!-- --- Footer --- -->
|
| 93 |
<footer>
|
| 94 |
<p>Made with ❤️ by <a href="https://asadfaizee.is-a.dev/" target="_blank" rel="noopener noreferrer">Asad Faizee</a></p>
|
| 95 |
</footer>
|
| 96 |
|
| 97 |
<script>
|
| 98 |
-
document.getElementById('repo-form')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
event.preventDefault();
|
| 100 |
const url = document.getElementById('repo-url').value;
|
| 101 |
-
const loader = document.getElementById('loader');
|
| 102 |
-
const resultContainer = document.getElementById('result-container');
|
| 103 |
-
const resultDiv = document.getElementById('result');
|
| 104 |
loader.style.display = 'block';
|
| 105 |
resultContainer.style.display = 'none';
|
| 106 |
resultDiv.textContent = '';
|
|
|
|
| 107 |
try {
|
| 108 |
const response = await fetch('/generate', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ url: url }) });
|
| 109 |
const data = await response.json();
|
| 110 |
-
if (response.ok) {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
resultContainer.style.display = 'block';
|
| 112 |
} catch (error) {
|
| 113 |
resultDiv.textContent = 'An unexpected error occurred: ' + error.toString();
|
|
@@ -116,6 +129,32 @@ HTML_TEMPLATE = """
|
|
| 116 |
loader.style.display = 'none';
|
| 117 |
}
|
| 118 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
</script>
|
| 120 |
</body>
|
| 121 |
</html>
|
|
@@ -161,7 +200,7 @@ def generate_readme_with_llm(repo_path):
|
|
| 161 |
|
| 162 |
try:
|
| 163 |
print("Step 5: Sending request to Gemini API...")
|
| 164 |
-
#
|
| 165 |
model = genai.GenerativeModel('gemini-2.5-flash')
|
| 166 |
|
| 167 |
response = model.generate_content(prompt)
|
|
|
|
| 35 |
color: #1c1e21;
|
| 36 |
margin: 0;
|
| 37 |
display: flex;
|
| 38 |
+
flex-direction: column;
|
| 39 |
justify-content: center;
|
| 40 |
align-items: center;
|
| 41 |
min-height: 100vh;
|
|
|
|
| 62 |
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
|
| 63 |
#result-container { display: none; margin-top: 20px; }
|
| 64 |
#result { margin-top: 10px; padding: 20px; background-color: #f7f7f7; border: 1px solid #dddfe2; border-radius: 6px; text-align: left; white-space: pre-wrap; font-family: 'Courier New', Courier, monospace; max-height: 400px; overflow-y: auto; word-wrap: break-word; }
|
| 65 |
+
.action-buttons { text-align: right; margin-top: 15px; }
|
| 66 |
+
.action-buttons button {
|
| 67 |
+
padding: 10px 20px;
|
| 68 |
+
border-radius: 6px;
|
| 69 |
+
background-color: #e4e6eb;
|
| 70 |
+
color: #1c1e21;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
font-weight: 600;
|
| 72 |
+
margin-left: 10px;
|
| 73 |
+
font-size: 0.9em;
|
| 74 |
}
|
| 75 |
+
.action-buttons button:hover { background-color: #d8dbdf; }
|
| 76 |
+
footer { margin-top: 25px; text-align: center; font-size: 0.9em; color: #8a8d91; }
|
| 77 |
+
footer a { color: #1877f2; text-decoration: none; font-weight: 600; }
|
| 78 |
+
footer a:hover { text-decoration: underline; }
|
| 79 |
</style>
|
| 80 |
</head>
|
| 81 |
<body>
|
|
|
|
| 84 |
<p>Enter a public GitHub repository URL and let a true AI agent analyze the code and generate a README for you.</p>
|
| 85 |
<form id="repo-form"><div class="input-group"><input type="url" id="repo-url" placeholder="e.g., https://github.com/user/project" required><button type="submit">Generate</button></div></form>
|
| 86 |
<div class="loader" id="loader"></div>
|
| 87 |
+
<div id="result-container">
|
| 88 |
+
<h2>Generated README.md:</h2>
|
| 89 |
+
<pre id="result"></pre>
|
| 90 |
+
<div class="action-buttons">
|
| 91 |
+
<button id="copy-btn">Copy</button>
|
| 92 |
+
<button id="download-btn">Download .md</button>
|
| 93 |
+
</div>
|
| 94 |
+
</div>
|
| 95 |
</div>
|
| 96 |
|
|
|
|
| 97 |
<footer>
|
| 98 |
<p>Made with ❤️ by <a href="https://asadfaizee.is-a.dev/" target="_blank" rel="noopener noreferrer">Asad Faizee</a></p>
|
| 99 |
</footer>
|
| 100 |
|
| 101 |
<script>
|
| 102 |
+
const repoForm = document.getElementById('repo-form');
|
| 103 |
+
const loader = document.getElementById('loader');
|
| 104 |
+
const resultContainer = document.getElementById('result-container');
|
| 105 |
+
const resultDiv = document.getElementById('result');
|
| 106 |
+
const copyBtn = document.getElementById('copy-btn');
|
| 107 |
+
const downloadBtn = document.getElementById('download-btn');
|
| 108 |
+
|
| 109 |
+
repoForm.addEventListener('submit', async function(event) {
|
| 110 |
event.preventDefault();
|
| 111 |
const url = document.getElementById('repo-url').value;
|
|
|
|
|
|
|
|
|
|
| 112 |
loader.style.display = 'block';
|
| 113 |
resultContainer.style.display = 'none';
|
| 114 |
resultDiv.textContent = '';
|
| 115 |
+
|
| 116 |
try {
|
| 117 |
const response = await fetch('/generate', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ url: url }) });
|
| 118 |
const data = await response.json();
|
| 119 |
+
if (response.ok) {
|
| 120 |
+
resultDiv.textContent = data.readme;
|
| 121 |
+
} else {
|
| 122 |
+
resultDiv.textContent = 'Error: ' + data.error;
|
| 123 |
+
}
|
| 124 |
resultContainer.style.display = 'block';
|
| 125 |
} catch (error) {
|
| 126 |
resultDiv.textContent = 'An unexpected error occurred: ' + error.toString();
|
|
|
|
| 129 |
loader.style.display = 'none';
|
| 130 |
}
|
| 131 |
});
|
| 132 |
+
|
| 133 |
+
copyBtn.addEventListener('click', function() {
|
| 134 |
+
const resultText = resultDiv.textContent;
|
| 135 |
+
const textArea = document.createElement('textarea');
|
| 136 |
+
textArea.value = resultText;
|
| 137 |
+
document.body.appendChild(textArea);
|
| 138 |
+
textArea.select();
|
| 139 |
+
document.execCommand('copy');
|
| 140 |
+
document.body.removeChild(textArea);
|
| 141 |
+
|
| 142 |
+
this.textContent = 'Copied!';
|
| 143 |
+
setTimeout(() => { this.textContent = 'Copy'; }, 2000);
|
| 144 |
+
});
|
| 145 |
+
|
| 146 |
+
downloadBtn.addEventListener('click', function() {
|
| 147 |
+
const resultText = resultDiv.textContent;
|
| 148 |
+
const blob = new Blob([resultText], { type: 'text/markdown' });
|
| 149 |
+
const url = URL.createObjectURL(blob);
|
| 150 |
+
const a = document.createElement('a');
|
| 151 |
+
a.href = url;
|
| 152 |
+
a.download = 'README.md';
|
| 153 |
+
document.body.appendChild(a);
|
| 154 |
+
a.click();
|
| 155 |
+
document.body.removeChild(a);
|
| 156 |
+
URL.revokeObjectURL(url);
|
| 157 |
+
});
|
| 158 |
</script>
|
| 159 |
</body>
|
| 160 |
</html>
|
|
|
|
| 200 |
|
| 201 |
try:
|
| 202 |
print("Step 5: Sending request to Gemini API...")
|
| 203 |
+
# Reverted model name back to user's preference.
|
| 204 |
model = genai.GenerativeModel('gemini-2.5-flash')
|
| 205 |
|
| 206 |
response = model.generate_content(prompt)
|