mirror of
https://github.com/vladmandic/sdnext.git
synced 2026-01-27 15:02:48 +03:00
67 lines
2.8 KiB
Python
67 lines
2.8 KiB
Python
import gradio as gr
|
|
from modules import ui_symbols, ui_components
|
|
|
|
|
|
def create_ui_logs():
|
|
def get_changelog():
|
|
with open('CHANGELOG.md', 'r', encoding='utf-8') as f:
|
|
content = f.read()
|
|
content = content.replace('# Change Log for SD.Next', ' ')
|
|
return content
|
|
|
|
with gr.Column():
|
|
get_changelog_btn = gr.Button(value='Get changelog', elem_id="get_changelog")
|
|
gr.HTML('<a href="https://github.com/vladmandic/sdnext/blob/dev/CHANGELOG.md" style="color: #AAA" target="_blank">  Open GitHub Changelog</a>')
|
|
with gr.Column():
|
|
_changelog_search = gr.Textbox(label="Search Changelog", elem_id="changelog_search")
|
|
_changelog_result = gr.HTML(elem_id="changelog_result")
|
|
|
|
changelog_markdown = gr.Markdown('', elem_id="changelog_markdown")
|
|
get_changelog_btn.click(fn=get_changelog, outputs=[changelog_markdown], show_progress=True)
|
|
|
|
|
|
def create_ui_wiki():
|
|
def search_github(search_term):
|
|
import requests
|
|
from urllib.parse import quote
|
|
from installer import install
|
|
|
|
install('beautifulsoup4')
|
|
from bs4 import BeautifulSoup
|
|
|
|
url = f'https://github.com/search?q=repo%3Avladmandic%2Fautomatic+{quote(search_term)}&type=wikis'
|
|
res = requests.get(url, timeout=10)
|
|
if res.status_code == 200:
|
|
html = res.content
|
|
soup = BeautifulSoup(html, 'html.parser')
|
|
|
|
# remove header links
|
|
tags = soup.find_all(attrs={"data-hovercard-url": "/vladmandic/sdnext/hovercard"})
|
|
for tag in tags:
|
|
tag.extract()
|
|
|
|
# replace relative links with full links
|
|
tags = soup.find_all('a')
|
|
for tag in tags:
|
|
if tag.has_attr('href') and tag['href'].startswith('/'):
|
|
tag['href'] = 'https://github.com' + tag['href']
|
|
|
|
# find result only
|
|
result = soup.find(attrs={"data-testid": "results-list"})
|
|
if result is None:
|
|
return 'No results found'
|
|
html = str(result)
|
|
return html
|
|
else:
|
|
return f'Error: {res.status_code}'
|
|
|
|
with gr.Row():
|
|
gr.HTML('<a href="https://github.com/vladmandic/sdnext/wiki" style="color: #AAA" target="_blank">  Open GitHub Wiki</a>')
|
|
with gr.Row():
|
|
wiki_search = gr.Textbox(label="Search Wiki Pages", elem_id="wiki_search")
|
|
wiki_search_btn = ui_components.ToolButton(value=ui_symbols.search, label="Search", elem_id="wiki_search_btn")
|
|
with gr.Row():
|
|
wiki_result = gr.HTML(elem_id="wiki_result", value='')
|
|
wiki_search.submit(_js="wikiSearch", fn=search_github, inputs=[wiki_search], outputs=[wiki_result])
|
|
wiki_search_btn.click(_js="wikiSearch", fn=search_github, inputs=[wiki_search], outputs=[wiki_result])
|