dwb2023 commited on
Commit
c7f9c4d
·
verified ·
1 Parent(s): 4006c1a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -13
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.filename,
10
- "type": "binary" if file_info.file_size > 1024 * 1024 else "text",
11
- "size": file_info.file_size,
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
- headers.append(file_summary)
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['filename']}"
36
  file_response = requests.get(file_url)
37
  if file_response.status_code == 200:
38
- file_content = file_response.text
39
- extracted_content.append({"header": file_summary, "content": file_content})
40
  else:
41
- extracted_content.append({"header": file_summary, "content": "Failed to fetch file content."})
42
  else:
43
- extracted_content.append({"header": file_summary, "content": "File too large or binary, content not captured."})
 
 
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