Spaces:
Runtime error
Runtime error
Upload find_and_create.sh with huggingface_hub
Browse files- find_and_create.sh +178 -0
find_and_create.sh
ADDED
@@ -0,0 +1,178 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/bin/bash
|
2 |
+
# Script to find and copy setup files
|
3 |
+
|
4 |
+
echo "Searching for setup_claude.sh and SETUP_INSTRUCTIONS.md..."
|
5 |
+
find / -name "setup_claude.sh" 2>/dev/null
|
6 |
+
find / -name "SETUP_INSTRUCTIONS.md" 2>/dev/null
|
7 |
+
|
8 |
+
# Create the files directly in the current directory
|
9 |
+
echo "Creating files directly..."
|
10 |
+
|
11 |
+
# Create setup_claude.sh
|
12 |
+
cat > setup_claude.sh << 'EOL'
|
13 |
+
#!/bin/bash
|
14 |
+
# Setup script for Claude in VS Code on Hugging Face Space
|
15 |
+
|
16 |
+
echo "Setting up Python environment for working with Claude..."
|
17 |
+
|
18 |
+
# Create a virtual environment
|
19 |
+
python -m venv ~/claude-env
|
20 |
+
|
21 |
+
# Activate the virtual environment
|
22 |
+
source ~/claude-env/bin/activate
|
23 |
+
|
24 |
+
# Install required packages
|
25 |
+
pip install -U huggingface_hub gradio transformers datasets sentence-transformers faiss-cpu torch langchain
|
26 |
+
|
27 |
+
# Create initial files
|
28 |
+
mkdir -p ~/hf_implementation
|
29 |
+
cd ~/hf_implementation
|
30 |
+
|
31 |
+
# Create a simple Gradio app
|
32 |
+
cat > app.py << 'EOF'
|
33 |
+
import gradio as gr
|
34 |
+
import os
|
35 |
+
|
36 |
+
def process_file(file):
|
37 |
+
"""Process an uploaded file."""
|
38 |
+
filename = os.path.basename(file.name)
|
39 |
+
return f"File {filename} would be processed using HF models."
|
40 |
+
|
41 |
+
def query_index(query):
|
42 |
+
"""Query the RAG index."""
|
43 |
+
return f"Query: {query}\nResponse: This is a placeholder. The real implementation will use sentence-transformers and FAISS."
|
44 |
+
|
45 |
+
# Create the Gradio interface
|
46 |
+
with gr.Blocks(title="RAG Document Processor") as demo:
|
47 |
+
gr.Markdown("# RAG Document Processing System")
|
48 |
+
|
49 |
+
with gr.Tab("Upload & Process"):
|
50 |
+
file_input = gr.File(label="Upload Document")
|
51 |
+
process_button = gr.Button("Process Document")
|
52 |
+
output = gr.Textbox(label="Processing Result")
|
53 |
+
process_button.click(process_file, inputs=file_input, outputs=output)
|
54 |
+
|
55 |
+
with gr.Tab("Query Documents"):
|
56 |
+
query_input = gr.Textbox(label="Enter your query")
|
57 |
+
query_button = gr.Button("Search")
|
58 |
+
response = gr.Textbox(label="Response")
|
59 |
+
query_button.click(query_index, inputs=query_input, outputs=response)
|
60 |
+
|
61 |
+
# Launch the app
|
62 |
+
if __name__ == "__main__":
|
63 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|
64 |
+
EOF
|
65 |
+
|
66 |
+
# Create a sample implementation file
|
67 |
+
cat > hf_embeddings.py << 'EOF'
|
68 |
+
"""
|
69 |
+
Embeddings module using sentence-transformers.
|
70 |
+
"""
|
71 |
+
from sentence_transformers import SentenceTransformer
|
72 |
+
import numpy as np
|
73 |
+
|
74 |
+
class HFEmbeddings:
|
75 |
+
def __init__(self, model_name="sentence-transformers/all-MiniLM-L6-v2"):
|
76 |
+
"""Initialize the embedding model.
|
77 |
+
|
78 |
+
Args:
|
79 |
+
model_name: Name of the sentence-transformers model to use
|
80 |
+
"""
|
81 |
+
self.model = SentenceTransformer(model_name)
|
82 |
+
|
83 |
+
def embed_texts(self, texts):
|
84 |
+
"""Generate embeddings for a list of texts.
|
85 |
+
|
86 |
+
Args:
|
87 |
+
texts: List of strings to embed
|
88 |
+
|
89 |
+
Returns:
|
90 |
+
List of embedding vectors
|
91 |
+
"""
|
92 |
+
return self.model.encode(texts)
|
93 |
+
|
94 |
+
def embed_query(self, query):
|
95 |
+
"""Generate embedding for a query string.
|
96 |
+
|
97 |
+
Args:
|
98 |
+
query: Query string
|
99 |
+
|
100 |
+
Returns:
|
101 |
+
Embedding vector
|
102 |
+
"""
|
103 |
+
return self.model.encode(query)
|
104 |
+
EOF
|
105 |
+
|
106 |
+
# Create a README for the implementation
|
107 |
+
cat > README.md << 'EOF'
|
108 |
+
# Hugging Face RAG Implementation
|
109 |
+
|
110 |
+
This directory contains the Hugging Face native implementation of the RAG system.
|
111 |
+
|
112 |
+
## Files
|
113 |
+
- `app.py` - Gradio interface for the RAG system
|
114 |
+
- `hf_embeddings.py` - Embedding generation with sentence-transformers
|
115 |
+
|
116 |
+
## Running the Application
|
117 |
+
```bash
|
118 |
+
python app.py
|
119 |
+
```
|
120 |
+
|
121 |
+
## Implementation Plan
|
122 |
+
See `CLAUDE_HF.md` in the main directory for the complete implementation plan.
|
123 |
+
EOF
|
124 |
+
|
125 |
+
echo "Setup complete!"
|
126 |
+
echo "To use the environment:"
|
127 |
+
echo "1. Run 'source ~/claude-env/bin/activate'"
|
128 |
+
echo "2. Navigate to '~/hf_implementation'"
|
129 |
+
echo "3. Run 'python app.py' to start the Gradio interface"
|
130 |
+
EOL
|
131 |
+
|
132 |
+
# Make the script executable
|
133 |
+
chmod +x setup_claude.sh
|
134 |
+
|
135 |
+
# Create SETUP_INSTRUCTIONS.md
|
136 |
+
cat > SETUP_INSTRUCTIONS.md << 'EOL'
|
137 |
+
# Using Claude with Hugging Face Space
|
138 |
+
|
139 |
+
Since you're facing permission issues in the VS Code terminal, follow these steps:
|
140 |
+
|
141 |
+
1. In the VS Code terminal, run:
|
142 |
+
```bash
|
143 |
+
chmod +x setup_claude.sh
|
144 |
+
./setup_claude.sh
|
145 |
+
```
|
146 |
+
|
147 |
+
2. This will:
|
148 |
+
- Create a Python virtual environment
|
149 |
+
- Install necessary packages
|
150 |
+
- Set up a basic implementation in ~/hf_implementation
|
151 |
+
|
152 |
+
3. After installation, activate the environment:
|
153 |
+
```bash
|
154 |
+
source ~/claude-env/bin/activate
|
155 |
+
```
|
156 |
+
|
157 |
+
4. Navigate to the implementation directory:
|
158 |
+
```bash
|
159 |
+
cd ~/hf_implementation
|
160 |
+
```
|
161 |
+
|
162 |
+
5. Run the Gradio app:
|
163 |
+
```bash
|
164 |
+
python app.py
|
165 |
+
```
|
166 |
+
|
167 |
+
## Next Steps
|
168 |
+
|
169 |
+
With this setup, you can:
|
170 |
+
1. Create the HF implementation files
|
171 |
+
2. Develop without root permissions
|
172 |
+
3. Run your RAG application with Hugging Face models
|
173 |
+
|
174 |
+
Refer to CLAUDE_HF.md for the implementation details.
|
175 |
+
EOL
|
176 |
+
|
177 |
+
echo "Files created successfully in the current directory."
|
178 |
+
echo "You can now run: ./setup_claude.sh"
|