# import re | |
# import requests | |
# import gradio as gr | |
# from markdownify import markdownify | |
# from requests.exceptions import RequestException | |
# from utils.preprocessor import Preprocessor | |
# # https://modal.com/docs/guide/webhook-urls | |
# MODAL_ENDPOINT = "https://auto-readme-agent--text-to-speech-gradio-app.modal.run" | |
# def visit_webpage(url, max_output_length=40000): | |
# """ | |
# Fetch the webpage, convert to markdown, and use Preprocessor methods. | |
# """ | |
# try: | |
# response = requests.get(url, timeout=20) | |
# response.raise_for_status() | |
# markdown_content = markdownify(response.text).strip() | |
# markdown_content = re.sub(r"\n{3,}", "\n\n", markdown_content) | |
# # if len(markdown_content) > max_output_length: | |
# # markdown_content = ( | |
# # markdown_content[: max_output_length // 2] | |
# # + f"\n..._This content has been truncated to stay below {max_output_length} characters_...\n" | |
# # + markdown_content[-max_output_length // 2 :] | |
# # ) | |
# # Use Preprocessor class methods | |
# section = Preprocessor.extract_section(markdown_content) | |
# dir_paths, files = Preprocessor.extract_dirs_from_text(section) | |
# # Format the result | |
# result = ( | |
# f"paths: {dir_paths}\n\n" | |
# f"files: {files}" | |
# ) | |
# return result | |
# except requests.exceptions.Timeout: | |
# return "The request timed out. Please try again later or check the URL." | |
# except RequestException as e: | |
# return f"Error fetching the webpage: {str(e)}" | |
# except Exception as e: | |
# return f"An unexpected error occurred: {str(e)}" | |
# demo = gr.Interface( | |
# fn=visit_webpage, | |
# inputs=[ | |
# gr.Textbox(label="Website URL"), | |
# gr.Textbox(label="Files or folders you want to highlight in the README (comma or newline separated)") | |
# ], | |
# outputs=gr.Textbox(label="Extracted Section, Directory Paths, and File Paths", show_copy_button=True), | |
# title="Webpage Section and Path Extractor", | |
# description="Enter a website URL. This tool fetches the page, extracts a markdown section, and lists directory paths and files found in that section. You can also specify files or folders you want to highlight in the generated README." | |
# ) | |
# if __name__ == "__main__": | |
# demo.launch(debug=True) | |
import re | |
import requests | |
import gradio as gr | |
from markdownify import markdownify | |
MODAL_API_URL = "https://agents-mcp-hackathon--auto-readme-agent-fastapi-app.modal.run" # Replace with your deployed Modal endpoint | |
# def generate_readme_from_github(repo_url): | |
# try: | |
# response = requests.post( | |
# MODAL_API_URL, | |
# json={"repo_url": repo_url}, | |
# timeout=180, | |
# ) | |
# if response.status_code == 200: | |
# return response.json().get("readme", "No README generated.") | |
# else: | |
# return f"Error: {response.status_code}\n{response.text}" | |
# except Exception as e: | |
# return f"Exception: {str(e)}" | |
# with gr.Blocks() as demo: | |
# gr.Markdown("# π GitHub Repo β README.md Generator\nPaste a public GitHub repo link to generate a draft README.md using AI.") | |
# repo_input = gr.Textbox(label="GitHub Repository URL", placeholder="https://github.com/owner/repo") | |
# output = gr.Textbox(label="Generated README.md", lines=20) | |
# btn = gr.Button("Generate README") | |
# btn.click(generate_readme_from_github, inputs=repo_input, outputs=output) | |
# if __name__ == "__main__": | |
# demo.launch() | |
def generate_readme(query): | |
try: | |
response = requests.post( | |
MODAL_API_URL, | |
json={"query": query}, | |
timeout=120 | |
) | |
if response.status_code == 200: | |
return response.json().get("result", "No result returned.") | |
else: | |
return f"Error: {response.status_code}\n{response.text}" | |
except Exception as e: | |
return f"Exception: {str(e)}" | |
def fetch_github_content(url: str) -> str: | |
try: | |
response = requests.get(url, timeout=20) | |
response.raise_for_status() | |
markdown_content = markdownify(response.text) | |
markdown_content = re.sub(r"\n{3,}", "\n\n", markdown_content) | |
return markdown_content | |
except Exception as e: | |
return f"Error fetching content: {str(e)}" | |
with gr.Blocks() as demo: | |
# μ λͺ© κ°μ΄λ° μ λ ¬ | |
gr.HTML("<h1 style='text-align:center;'>π€ ARA: Auto README.md Agent π</h1>") | |
repo_input = gr.Textbox( | |
label="GitHub Repository URL", | |
placeholder="Enter the GitHub repository URL (e.g. https://github.com/username/repo)" | |
) | |
with gr.Row(): | |
with gr.Column(): | |
gr.Markdown("#### πΌοΈ Preview (Markdown Rendered)") | |
# μΌμͺ½: μμ κ°λ₯ν ν리뷰 λ°μ€ | |
readme_preview = gr.Textbox( | |
lines=24, | |
label="Preview (Markdown Rendered)", | |
interactive=True | |
) | |
with gr.Column(): | |
gr.Markdown("#### π Markdown File (Copyable)") | |
# μ€λ₯Έμͺ½: μμ λΆκ°, λ³΅μ¬ λ²νΌ μλ λ°μ€ | |
readme_markdown = gr.Textbox( | |
lines=24, | |
label="Markdown", | |
interactive=False, | |
show_copy_button=True | |
) | |
generate_btn = gr.Button("Generate README.md") | |
# λ²νΌ ν΄λ¦ μ λ λ°μ€ λͺ¨λ μ±μ | |
def dual_output(readme): | |
return readme, readme | |
generate_btn.click( | |
generate_readme, | |
inputs=repo_input, | |
outputs=[readme_preview, readme_markdown] | |
) | |
if __name__ == "__main__": | |
demo.launch() |