naman1102 commited on
Commit
b138e3b
·
1 Parent(s): 63c0f13
Files changed (3) hide show
  1. app.py +15 -3
  2. hf_utils.py +53 -0
  3. requirements.txt +4 -1
app.py CHANGED
@@ -1,17 +1,29 @@
1
  import gradio as gr
2
  import re
 
 
 
3
 
4
  def process_repo_input(text):
5
  if not text:
6
- return "No repo IDs provided."
7
  # Split by newlines and commas, strip whitespace
8
  repo_ids = [repo.strip() for repo in re.split(r'[\n,]+', text) if repo.strip()]
9
- return f"Entered repo IDs: {', '.join(repo_ids)}"
 
 
 
 
 
 
 
 
 
10
 
11
  demo = gr.Interface(
12
  fn=process_repo_input,
13
  inputs=gr.Textbox(label="Enter repo IDs (comma or newline separated)", lines=5, placeholder="repo1, repo2\nrepo3"),
14
- outputs="text",
15
  title="Repo ID Input",
16
  description="Enter repo IDs separated by commas or new lines."
17
  )
 
1
  import gradio as gr
2
  import re
3
+ import csv
4
+ import pandas as pd
5
+
6
 
7
  def process_repo_input(text):
8
  if not text:
9
+ return pd.DataFrame(columns=["repo id", "strength", "weaknesses", "speciality", "relevance rating"])
10
  # Split by newlines and commas, strip whitespace
11
  repo_ids = [repo.strip() for repo in re.split(r'[\n,]+', text) if repo.strip()]
12
+ # Write to CSV
13
+ csv_filename = "repo_ids.csv"
14
+ with open(csv_filename, mode="w", newline='', encoding="utf-8") as csvfile:
15
+ writer = csv.writer(csvfile)
16
+ writer.writerow(["repo id", "strength", "weaknesses", "speciality", "relevance rating"])
17
+ for repo_id in repo_ids:
18
+ writer.writerow([repo_id, "", "", "", ""])
19
+ # Read the CSV into a DataFrame to display
20
+ df = pd.read_csv(csv_filename)
21
+ return df
22
 
23
  demo = gr.Interface(
24
  fn=process_repo_input,
25
  inputs=gr.Textbox(label="Enter repo IDs (comma or newline separated)", lines=5, placeholder="repo1, repo2\nrepo3"),
26
+ outputs=gr.Dataframe(headers=["repo id", "strength", "weaknesses", "speciality", "relevance rating"]),
27
  title="Repo ID Input",
28
  description="Enter repo IDs separated by commas or new lines."
29
  )
hf_utils.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from huggingface_hub import snapshot_download
2
+ import os
3
+ import shutil
4
+
5
+ def download_space_repo(space_id: str, local_dir: str = "space_repo"):
6
+ """
7
+ Downloads all files from a Hugging Face Space repository.
8
+
9
+ Args:
10
+ space_id (str): The ID of the Hugging Face Space (e.g., "naman1102/Final_Assignment_Template").
11
+ local_dir (str): Local directory to store the downloaded files.
12
+ """
13
+ print(f"Downloading Space '{space_id}'...")
14
+
15
+ # Download the snapshot of the space repo
16
+ repo_path = snapshot_download(repo_id=space_id, repo_type="space")
17
+
18
+ # Remove existing directory if it exists
19
+ if os.path.exists(local_dir):
20
+ shutil.rmtree(local_dir)
21
+
22
+ # Copy contents to target directory
23
+ shutil.copytree(repo_path, local_dir)
24
+
25
+ print(f"All files from Space '{space_id}' downloaded to: {local_dir}")
26
+
27
+ # Example usage
28
+ # download_space_repo("finegrain/finegrain-image-enhancer")
29
+
30
+ from huggingface_hub import list_spaces
31
+
32
+ def search_top_spaces(query: str, limit: int = 5):
33
+ """
34
+ Search and return top Hugging Face Space repo IDs based on a keyword.
35
+
36
+ Args:
37
+ query (str): The keyword to search for (e.g., "image", "chatbot").
38
+ limit (int): Maximum number of results to return.
39
+
40
+ Returns:
41
+ List of repo IDs.
42
+ """
43
+ results = list(list_spaces(search=query, sort="likes", direction=-1)) # Convert generator to list
44
+ top_spaces = [space.id for space in results[:limit]]
45
+
46
+ return top_spaces
47
+
48
+ # Example usage
49
+ # top_image_spaces = search_top_spaces("tic tac toe", limit=10)
50
+ # print("Top games-related Spaces:")
51
+ # for space_id in top_image_spaces:
52
+ # print("-", space_id)
53
+
requirements.txt CHANGED
@@ -1 +1,4 @@
1
- gradio
 
 
 
 
1
+ gradio
2
+ pandas
3
+ re
4
+ csv