# 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 gradio as gr | |
import requests | |
MODAL_API_URL = "https://agents-mcp-hackathon--smolagents-modal-agent-readme-agen-eb6ccb.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=600, | |
) | |
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() |