Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -1,14 +1,11 @@
|
|
1 |
-
import os
|
2 |
import requests
|
3 |
-
import zipfile
|
4 |
-
import io
|
5 |
import gradio as gr
|
6 |
|
7 |
def get_file_summary(file_info):
|
8 |
return {
|
9 |
-
"name": file_info
|
10 |
-
"type": "binary" if file_info
|
11 |
-
"size": file_info
|
12 |
}
|
13 |
|
14 |
def extract_repo_content(url):
|
@@ -25,22 +22,22 @@ def extract_repo_content(url):
|
|
25 |
|
26 |
repo_content = response.json()
|
27 |
extracted_content = []
|
28 |
-
headers = []
|
29 |
|
30 |
for file_info in repo_content:
|
31 |
file_summary = get_file_summary(file_info)
|
32 |
-
|
33 |
|
34 |
if file_summary["type"] == "text" and file_summary["size"] <= 1024 * 1024:
|
35 |
-
file_url = f"https://huggingface.co/{repo_type}/{repo_name}/resolve/main/{file_info['
|
36 |
file_response = requests.get(file_url)
|
37 |
if file_response.status_code == 200:
|
38 |
-
|
39 |
-
extracted_content.append({"header": file_summary, "content": file_content})
|
40 |
else:
|
41 |
-
|
42 |
else:
|
43 |
-
|
|
|
|
|
44 |
|
45 |
return extracted_content
|
46 |
|
|
|
|
|
1 |
import requests
|
|
|
|
|
2 |
import gradio as gr
|
3 |
|
4 |
def get_file_summary(file_info):
|
5 |
return {
|
6 |
+
"name": file_info['path'],
|
7 |
+
"type": "binary" if file_info['size'] > 1024 * 1024 else "text",
|
8 |
+
"size": file_info['size'],
|
9 |
}
|
10 |
|
11 |
def extract_repo_content(url):
|
|
|
22 |
|
23 |
repo_content = response.json()
|
24 |
extracted_content = []
|
|
|
25 |
|
26 |
for file_info in repo_content:
|
27 |
file_summary = get_file_summary(file_info)
|
28 |
+
content = {"header": file_summary}
|
29 |
|
30 |
if file_summary["type"] == "text" and file_summary["size"] <= 1024 * 1024:
|
31 |
+
file_url = f"https://huggingface.co/{repo_type}/{repo_name}/resolve/main/{file_info['path']}"
|
32 |
file_response = requests.get(file_url)
|
33 |
if file_response.status_code == 200:
|
34 |
+
content["content"] = file_response.text
|
|
|
35 |
else:
|
36 |
+
content["content"] = "Failed to fetch file content."
|
37 |
else:
|
38 |
+
content["content"] = "File too large or binary, content not captured."
|
39 |
+
|
40 |
+
extracted_content.append(content)
|
41 |
|
42 |
return extracted_content
|
43 |
|