Spaces:
Running
on
Zero
Running
on
Zero
Rename app.py to main.py
Browse files- app.py β main.py +25 -2
app.py β main.py
RENAMED
@@ -1,8 +1,31 @@
|
|
|
|
1 |
import gradio as gr
|
2 |
from repo_utils import extract_repo_content
|
3 |
-
from display_utils import format_output
|
4 |
|
5 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
def extract_and_display(url):
|
7 |
extracted_content = extract_repo_content(url, hf_token, hf_user)
|
8 |
formatted_output = format_output(extracted_content, url)
|
|
|
1 |
+
import os
|
2 |
import gradio as gr
|
3 |
from repo_utils import extract_repo_content
|
|
|
4 |
|
5 |
+
# Get the HF token and space author name from environment variables
|
6 |
+
hf_token = os.getenv("HF_TOKEN")
|
7 |
+
hf_user = os.getenv("SPACE_AUTHOR_NAME")
|
8 |
+
|
9 |
+
if not hf_token:
|
10 |
+
raise ValueError("HF_TOKEN environment variable is not set")
|
11 |
+
if not hf_user:
|
12 |
+
raise ValueError("SPACE_AUTHOR_NAME environment variable is not set")
|
13 |
+
|
14 |
+
def format_output(extracted_content, repo_url):
|
15 |
+
formatted_output = f"# Repository URL: {repo_url}\n\n"
|
16 |
+
for file_data in extracted_content:
|
17 |
+
if isinstance(file_data, dict) and 'header' in file_data:
|
18 |
+
formatted_output += f"### File: {file_data['header']['name']}\n"
|
19 |
+
formatted_output += f"**Type:** {file_data['header']['type']}\n"
|
20 |
+
formatted_output += f"**Size:** {file_data['header']['size']} bytes\n"
|
21 |
+
formatted_output += f"**Created:** {file_data['header']['creation_date']}\n"
|
22 |
+
formatted_output += f"**Modified:** {file_data['header']['modification_date']}\n"
|
23 |
+
formatted_output += "#### Content:\n"
|
24 |
+
formatted_output += f"```\n{file_data['content']}\n```\n\n"
|
25 |
+
else:
|
26 |
+
formatted_output += "Error in file data format.\n"
|
27 |
+
return formatted_output
|
28 |
+
|
29 |
def extract_and_display(url):
|
30 |
extracted_content = extract_repo_content(url, hf_token, hf_user)
|
31 |
formatted_output = format_output(extracted_content, url)
|