Spaces:
Runtime error
Runtime error
Upload setup_claude.sh with huggingface_hub
Browse files- setup_claude.sh +117 -0
setup_claude.sh
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
# Setup script for Claude in VS Code on Hugging Face Space
|
| 3 |
+
|
| 4 |
+
echo "Setting up Python environment for working with Claude..."
|
| 5 |
+
|
| 6 |
+
# Create a virtual environment
|
| 7 |
+
python -m venv ~/claude-env
|
| 8 |
+
|
| 9 |
+
# Activate the virtual environment
|
| 10 |
+
source ~/claude-env/bin/activate
|
| 11 |
+
|
| 12 |
+
# Install required packages
|
| 13 |
+
pip install -U huggingface_hub gradio transformers datasets sentence-transformers faiss-cpu torch langchain
|
| 14 |
+
|
| 15 |
+
# Create initial files
|
| 16 |
+
mkdir -p ~/hf_implementation
|
| 17 |
+
cd ~/hf_implementation
|
| 18 |
+
|
| 19 |
+
# Create a simple Gradio app
|
| 20 |
+
cat > app.py << 'EOL'
|
| 21 |
+
import gradio as gr
|
| 22 |
+
import os
|
| 23 |
+
|
| 24 |
+
def process_file(file):
|
| 25 |
+
"""Process an uploaded file."""
|
| 26 |
+
filename = os.path.basename(file.name)
|
| 27 |
+
return f"File {filename} would be processed using HF models."
|
| 28 |
+
|
| 29 |
+
def query_index(query):
|
| 30 |
+
"""Query the RAG index."""
|
| 31 |
+
return f"Query: {query}\nResponse: This is a placeholder. The real implementation will use sentence-transformers and FAISS."
|
| 32 |
+
|
| 33 |
+
# Create the Gradio interface
|
| 34 |
+
with gr.Blocks(title="RAG Document Processor") as demo:
|
| 35 |
+
gr.Markdown("# RAG Document Processing System")
|
| 36 |
+
|
| 37 |
+
with gr.Tab("Upload & Process"):
|
| 38 |
+
file_input = gr.File(label="Upload Document")
|
| 39 |
+
process_button = gr.Button("Process Document")
|
| 40 |
+
output = gr.Textbox(label="Processing Result")
|
| 41 |
+
process_button.click(process_file, inputs=file_input, outputs=output)
|
| 42 |
+
|
| 43 |
+
with gr.Tab("Query Documents"):
|
| 44 |
+
query_input = gr.Textbox(label="Enter your query")
|
| 45 |
+
query_button = gr.Button("Search")
|
| 46 |
+
response = gr.Textbox(label="Response")
|
| 47 |
+
query_button.click(query_index, inputs=query_input, outputs=response)
|
| 48 |
+
|
| 49 |
+
# Launch the app
|
| 50 |
+
if __name__ == "__main__":
|
| 51 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|
| 52 |
+
EOL
|
| 53 |
+
|
| 54 |
+
# Create a sample implementation file
|
| 55 |
+
cat > hf_embeddings.py << 'EOL'
|
| 56 |
+
"""
|
| 57 |
+
Embeddings module using sentence-transformers.
|
| 58 |
+
"""
|
| 59 |
+
from sentence_transformers import SentenceTransformer
|
| 60 |
+
import numpy as np
|
| 61 |
+
|
| 62 |
+
class HFEmbeddings:
|
| 63 |
+
def __init__(self, model_name="sentence-transformers/all-MiniLM-L6-v2"):
|
| 64 |
+
"""Initialize the embedding model.
|
| 65 |
+
|
| 66 |
+
Args:
|
| 67 |
+
model_name: Name of the sentence-transformers model to use
|
| 68 |
+
"""
|
| 69 |
+
self.model = SentenceTransformer(model_name)
|
| 70 |
+
|
| 71 |
+
def embed_texts(self, texts):
|
| 72 |
+
"""Generate embeddings for a list of texts.
|
| 73 |
+
|
| 74 |
+
Args:
|
| 75 |
+
texts: List of strings to embed
|
| 76 |
+
|
| 77 |
+
Returns:
|
| 78 |
+
List of embedding vectors
|
| 79 |
+
"""
|
| 80 |
+
return self.model.encode(texts)
|
| 81 |
+
|
| 82 |
+
def embed_query(self, query):
|
| 83 |
+
"""Generate embedding for a query string.
|
| 84 |
+
|
| 85 |
+
Args:
|
| 86 |
+
query: Query string
|
| 87 |
+
|
| 88 |
+
Returns:
|
| 89 |
+
Embedding vector
|
| 90 |
+
"""
|
| 91 |
+
return self.model.encode(query)
|
| 92 |
+
EOL
|
| 93 |
+
|
| 94 |
+
# Create a README for the implementation
|
| 95 |
+
cat > README.md << 'EOL'
|
| 96 |
+
# Hugging Face RAG Implementation
|
| 97 |
+
|
| 98 |
+
This directory contains the Hugging Face native implementation of the RAG system.
|
| 99 |
+
|
| 100 |
+
## Files
|
| 101 |
+
- `app.py` - Gradio interface for the RAG system
|
| 102 |
+
- `hf_embeddings.py` - Embedding generation with sentence-transformers
|
| 103 |
+
|
| 104 |
+
## Running the Application
|
| 105 |
+
```bash
|
| 106 |
+
python app.py
|
| 107 |
+
```
|
| 108 |
+
|
| 109 |
+
## Implementation Plan
|
| 110 |
+
See `CLAUDE_HF.md` in the main directory for the complete implementation plan.
|
| 111 |
+
EOL
|
| 112 |
+
|
| 113 |
+
echo "Setup complete!"
|
| 114 |
+
echo "To use the environment:"
|
| 115 |
+
echo "1. Run 'source ~/claude-env/bin/activate'"
|
| 116 |
+
echo "2. Navigate to '~/hf_implementation'"
|
| 117 |
+
echo "3. Run 'python app.py' to start the Gradio interface"
|