Spaces:
Paused
Paused
Upload folder using huggingface_hub
Browse files
app.py
CHANGED
|
@@ -127,7 +127,7 @@ def setup_mkslides():
|
|
| 127 |
setup_mkslides()
|
| 128 |
|
| 129 |
import gradio as gr
|
| 130 |
-
from github import Github
|
| 131 |
import requests
|
| 132 |
from openai import OpenAI
|
| 133 |
import logging
|
|
@@ -154,7 +154,7 @@ BLABLADOR_BASE_URL = "https://api.helmholtz-blablador.fz-juelich.de/v1"
|
|
| 154 |
JULES_API_URL = "https://jules.googleapis.com/v1alpha"
|
| 155 |
|
| 156 |
# GitHub Client
|
| 157 |
-
gh = Github(GITHUB_TOKEN) if GITHUB_TOKEN else None
|
| 158 |
REPO_NAME = "JsonLord/tiny_web"
|
| 159 |
POOL_REPO_NAME = "JsonLord/agent-notes"
|
| 160 |
POOL_PATH = "PersonaPool"
|
|
@@ -685,14 +685,17 @@ def get_reports_in_branch(repo_full_name, branch_name):
|
|
| 685 |
repo = gh.get_repo(repo_full_name)
|
| 686 |
add_log(f"Scanning branch {branch_name} for reports...")
|
| 687 |
|
|
|
|
|
|
|
| 688 |
# Method 1: Check user_experience_reports directory
|
| 689 |
reports = []
|
| 690 |
try:
|
| 691 |
contents = repo.get_contents("user_experience_reports", ref=branch_name)
|
| 692 |
for content_file in contents:
|
| 693 |
name = content_file.name
|
| 694 |
-
if name.endswith(".md")
|
| 695 |
-
|
|
|
|
| 696 |
except:
|
| 697 |
pass
|
| 698 |
|
|
@@ -702,22 +705,34 @@ def get_reports_in_branch(repo_full_name, branch_name):
|
|
| 702 |
for element in tree:
|
| 703 |
if element.type == "blob" and element.path.endswith(".md"):
|
| 704 |
path = element.path
|
|
|
|
|
|
|
|
|
|
| 705 |
if path not in reports:
|
| 706 |
reports.append(path)
|
| 707 |
|
| 708 |
-
# Sort by relevance
|
| 709 |
def sort_key(path):
|
| 710 |
p_lower = path.lower()
|
| 711 |
score = 0
|
| 712 |
-
|
| 713 |
-
if "report"
|
| 714 |
-
if
|
| 715 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 716 |
return (score, p_lower)
|
| 717 |
|
| 718 |
reports.sort(key=sort_key)
|
| 719 |
|
| 720 |
-
add_log(f"Discovered {len(reports)}
|
| 721 |
return reports
|
| 722 |
except Exception as e:
|
| 723 |
add_log(f"Error fetching reports in branch {branch_name}: {e}")
|
|
@@ -730,10 +745,14 @@ def get_report_content(repo_full_name, branch_name, report_path):
|
|
| 730 |
return "Please select a repository, branch, and report."
|
| 731 |
try:
|
| 732 |
repo = gh.get_repo(repo_full_name)
|
| 733 |
-
add_log(f"Fetching content
|
| 734 |
file_content = repo.get_contents(report_path, ref=branch_name)
|
| 735 |
return file_content.decoded_content.decode("utf-8")
|
| 736 |
except Exception as e:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 737 |
add_log(f"Error fetching {report_path}: {e}")
|
| 738 |
return f"Error fetching report: {str(e)}"
|
| 739 |
|
|
@@ -784,30 +803,38 @@ def render_slides(repo_full_name, branch_name, report_path):
|
|
| 784 |
try:
|
| 785 |
repo = gh.get_repo(repo_full_name)
|
| 786 |
|
| 787 |
-
#
|
| 788 |
if "slide" in report_path.lower():
|
| 789 |
slides_path = report_path
|
|
|
|
|
|
|
| 790 |
else:
|
| 791 |
-
# Try to
|
| 792 |
-
|
| 793 |
-
slides_path = report_path
|
| 794 |
-
|
|
|
|
|
|
|
| 795 |
|
| 796 |
try:
|
| 797 |
file_content = repo.get_contents(slides_path, ref=branch_name)
|
| 798 |
content = file_content.decoded_content.decode("utf-8")
|
| 799 |
-
except:
|
| 800 |
-
|
| 801 |
-
|
| 802 |
-
|
| 803 |
-
|
| 804 |
-
|
| 805 |
-
|
| 806 |
-
|
| 807 |
-
|
| 808 |
-
|
|
|
|
|
|
|
|
|
|
| 809 |
else:
|
| 810 |
-
|
|
|
|
| 811 |
|
| 812 |
# Prepare workspace
|
| 813 |
report_id = str(uuid.uuid4())[:8]
|
|
@@ -973,7 +1000,7 @@ with gr.Blocks() as demo:
|
|
| 973 |
try:
|
| 974 |
if token:
|
| 975 |
add_log(f"Testing connection with provided token...")
|
| 976 |
-
test_gh = Github(token)
|
| 977 |
elif gh:
|
| 978 |
add_log(f"Testing connection with existing client...")
|
| 979 |
test_gh = gh
|
|
|
|
| 127 |
setup_mkslides()
|
| 128 |
|
| 129 |
import gradio as gr
|
| 130 |
+
from github import Github, Auth
|
| 131 |
import requests
|
| 132 |
from openai import OpenAI
|
| 133 |
import logging
|
|
|
|
| 154 |
JULES_API_URL = "https://jules.googleapis.com/v1alpha"
|
| 155 |
|
| 156 |
# GitHub Client
|
| 157 |
+
gh = Github(auth=Auth.Token(GITHUB_TOKEN)) if GITHUB_TOKEN else None
|
| 158 |
REPO_NAME = "JsonLord/tiny_web"
|
| 159 |
POOL_REPO_NAME = "JsonLord/agent-notes"
|
| 160 |
POOL_PATH = "PersonaPool"
|
|
|
|
| 685 |
repo = gh.get_repo(repo_full_name)
|
| 686 |
add_log(f"Scanning branch {branch_name} for reports...")
|
| 687 |
|
| 688 |
+
exclude_files = {"jules_template.md", "readme.md", "contributing.md", "license.md"}
|
| 689 |
+
|
| 690 |
# Method 1: Check user_experience_reports directory
|
| 691 |
reports = []
|
| 692 |
try:
|
| 693 |
contents = repo.get_contents("user_experience_reports", ref=branch_name)
|
| 694 |
for content_file in contents:
|
| 695 |
name = content_file.name
|
| 696 |
+
if name.endswith(".md"):
|
| 697 |
+
path = f"user_experience_reports/{name}"
|
| 698 |
+
reports.append(path)
|
| 699 |
except:
|
| 700 |
pass
|
| 701 |
|
|
|
|
| 705 |
for element in tree:
|
| 706 |
if element.type == "blob" and element.path.endswith(".md"):
|
| 707 |
path = element.path
|
| 708 |
+
filename = os.path.basename(path).lower()
|
| 709 |
+
if filename in exclude_files:
|
| 710 |
+
continue
|
| 711 |
if path not in reports:
|
| 712 |
reports.append(path)
|
| 713 |
|
| 714 |
+
# Sort by relevance
|
| 715 |
def sort_key(path):
|
| 716 |
p_lower = path.lower()
|
| 717 |
score = 0
|
| 718 |
+
# Highest priority: specific report.md and slides.md in user_experience_reports
|
| 719 |
+
if p_lower == "user_experience_reports/report.md": score -= 1000
|
| 720 |
+
if p_lower == "user_experience_reports/slides.md": score -= 900
|
| 721 |
+
|
| 722 |
+
# High priority: other files in user_experience_reports
|
| 723 |
+
if "user_experience_reports" in p_lower: score -= 100
|
| 724 |
+
|
| 725 |
+
# Medium priority: keywords in filename
|
| 726 |
+
filename = os.path.basename(p_lower)
|
| 727 |
+
if "report" in filename: score -= 50
|
| 728 |
+
if "slide" in filename: score -= 30
|
| 729 |
+
if "ux" in filename: score -= 20
|
| 730 |
+
|
| 731 |
return (score, p_lower)
|
| 732 |
|
| 733 |
reports.sort(key=sort_key)
|
| 734 |
|
| 735 |
+
add_log(f"Discovered {len(reports)} potential Markdown files.")
|
| 736 |
return reports
|
| 737 |
except Exception as e:
|
| 738 |
add_log(f"Error fetching reports in branch {branch_name}: {e}")
|
|
|
|
| 745 |
return "Please select a repository, branch, and report."
|
| 746 |
try:
|
| 747 |
repo = gh.get_repo(repo_full_name)
|
| 748 |
+
add_log(f"Fetching content from branch '{branch_name}' at path: {report_path}")
|
| 749 |
file_content = repo.get_contents(report_path, ref=branch_name)
|
| 750 |
return file_content.decoded_content.decode("utf-8")
|
| 751 |
except Exception as e:
|
| 752 |
+
msg = str(e)
|
| 753 |
+
if "404" in msg:
|
| 754 |
+
add_log(f"ERROR: File not found: {report_path} in branch {branch_name}")
|
| 755 |
+
return f"Error: File '{report_path}' not found in branch '{branch_name}'. Please verify the path and branch."
|
| 756 |
add_log(f"Error fetching {report_path}: {e}")
|
| 757 |
return f"Error fetching report: {str(e)}"
|
| 758 |
|
|
|
|
| 803 |
try:
|
| 804 |
repo = gh.get_repo(repo_full_name)
|
| 805 |
|
| 806 |
+
# Determine slides path
|
| 807 |
if "slide" in report_path.lower():
|
| 808 |
slides_path = report_path
|
| 809 |
+
elif report_path == "user_experience_reports/report.md":
|
| 810 |
+
slides_path = "user_experience_reports/slides.md"
|
| 811 |
else:
|
| 812 |
+
# Try to map report_ID.md to slides_ID.md
|
| 813 |
+
slides_path = report_path.replace("report_", "slides_")
|
| 814 |
+
if slides_path == report_path: # No replacement happened
|
| 815 |
+
slides_path = "user_experience_reports/slides.md" # fallback
|
| 816 |
+
|
| 817 |
+
add_log(f"Attempting to fetch slides from branch '{branch_name}' at path: {slides_path}")
|
| 818 |
|
| 819 |
try:
|
| 820 |
file_content = repo.get_contents(slides_path, ref=branch_name)
|
| 821 |
content = file_content.decoded_content.decode("utf-8")
|
| 822 |
+
except Exception as e:
|
| 823 |
+
if "404" in str(e):
|
| 824 |
+
add_log(f"Slides file not found at {slides_path}. Attempting fallback...")
|
| 825 |
+
# Last resort fallback: look for any .md file with 'slides' in the name in the same branch
|
| 826 |
+
reports = get_reports_in_branch(repo_full_name, branch_name)
|
| 827 |
+
slides_files = [r for r in reports if "slide" in r.lower()]
|
| 828 |
+
if slides_files:
|
| 829 |
+
slides_path = slides_files[0]
|
| 830 |
+
add_log(f"Found alternative slides file: {slides_path}")
|
| 831 |
+
file_content = repo.get_contents(slides_path, ref=branch_name)
|
| 832 |
+
content = file_content.decoded_content.decode("utf-8")
|
| 833 |
+
else:
|
| 834 |
+
return f"Error: File '{slides_path}' not found in branch '{branch_name}'. No other slide files discovered."
|
| 835 |
else:
|
| 836 |
+
add_log(f"Error fetching slides: {e}")
|
| 837 |
+
return f"Error fetching slides: {str(e)}"
|
| 838 |
|
| 839 |
# Prepare workspace
|
| 840 |
report_id = str(uuid.uuid4())[:8]
|
|
|
|
| 1000 |
try:
|
| 1001 |
if token:
|
| 1002 |
add_log(f"Testing connection with provided token...")
|
| 1003 |
+
test_gh = Github(auth=Auth.Token(token))
|
| 1004 |
elif gh:
|
| 1005 |
add_log(f"Testing connection with existing client...")
|
| 1006 |
test_gh = gh
|