Spaces:
No application file
No application file
Commit ·
5d939a0
1
Parent(s): bfd28a0
init
Browse files- .idea/.gitignore +3 -0
- .idea/.gitignore:Zone.Identifier +0 -0
- .idea/hugging-face.iml +8 -0
- .idea/hugging-face.iml:Zone.Identifier +0 -0
- .idea/inspectionProfiles/profiles_settings.xml +6 -0
- .idea/inspectionProfiles/profiles_settings.xml:Zone.Identifier +0 -0
- .idea/misc.xml +7 -0
- .idea/misc.xml:Zone.Identifier +0 -0
- .idea/modules.xml +8 -0
- .idea/modules.xml:Zone.Identifier +0 -0
- .idea/workspace.xml:Zone.Identifier +0 -0
- app.py +29 -0
- app.py:Zone.Identifier +0 -0
- dockerfile +17 -0
- dockerfile:Zone.Identifier +0 -0
- requirements.txt +6 -0
- requirements.txt:Zone.Identifier +0 -0
.idea/.gitignore
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Default ignored files
|
| 2 |
+
/shelf/
|
| 3 |
+
/workspace.xml
|
.idea/.gitignore:Zone.Identifier
ADDED
|
File without changes
|
.idea/hugging-face.iml
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
| 2 |
+
<module type="PYTHON_MODULE" version="4">
|
| 3 |
+
<component name="NewModuleRootManager">
|
| 4 |
+
<content url="file://$MODULE_DIR$" />
|
| 5 |
+
<orderEntry type="jdk" jdkName="Python 3.13" jdkType="Python SDK" />
|
| 6 |
+
<orderEntry type="sourceFolder" forTests="false" />
|
| 7 |
+
</component>
|
| 8 |
+
</module>
|
.idea/hugging-face.iml:Zone.Identifier
ADDED
|
File without changes
|
.idea/inspectionProfiles/profiles_settings.xml
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<component name="InspectionProjectProfileManager">
|
| 2 |
+
<settings>
|
| 3 |
+
<option name="USE_PROJECT_PROFILE" value="false" />
|
| 4 |
+
<version value="1.0" />
|
| 5 |
+
</settings>
|
| 6 |
+
</component>
|
.idea/inspectionProfiles/profiles_settings.xml:Zone.Identifier
ADDED
|
File without changes
|
.idea/misc.xml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
| 2 |
+
<project version="4">
|
| 3 |
+
<component name="Black">
|
| 4 |
+
<option name="sdkName" value="Python 3.13" />
|
| 5 |
+
</component>
|
| 6 |
+
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.13" project-jdk-type="Python SDK" />
|
| 7 |
+
</project>
|
.idea/misc.xml:Zone.Identifier
ADDED
|
File without changes
|
.idea/modules.xml
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
| 2 |
+
<project version="4">
|
| 3 |
+
<component name="ProjectModuleManager">
|
| 4 |
+
<modules>
|
| 5 |
+
<module fileurl="file://$PROJECT_DIR$/.idea/hugging-face.iml" filepath="$PROJECT_DIR$/.idea/hugging-face.iml" />
|
| 6 |
+
</modules>
|
| 7 |
+
</component>
|
| 8 |
+
</project>
|
.idea/modules.xml:Zone.Identifier
ADDED
|
File without changes
|
.idea/workspace.xml:Zone.Identifier
ADDED
|
File without changes
|
app.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from flask import Flask, request, jsonify
|
| 2 |
+
import torch
|
| 3 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 4 |
+
|
| 5 |
+
app = Flask(__name__)
|
| 6 |
+
|
| 7 |
+
MODEL_NAME = "meta-llama/Llama-2-7b-chat-hf" # Ensure you have access!
|
| 8 |
+
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME, use_auth_token=True)
|
| 9 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 10 |
+
MODEL_NAME, torch_dtype=torch.float16, device_map="auto", use_auth_token=True
|
| 11 |
+
)
|
| 12 |
+
|
| 13 |
+
@app.route('/generate', methods=['POST'])
|
| 14 |
+
def generate():
|
| 15 |
+
user_request = request.json.get("query")
|
| 16 |
+
if not user_request:
|
| 17 |
+
return jsonify({"error": "No query provided"}), 400
|
| 18 |
+
|
| 19 |
+
mongo_query = generate_mongo_query(user_request)
|
| 20 |
+
return jsonify({"mongo_query": mongo_query})
|
| 21 |
+
|
| 22 |
+
def generate_mongo_query(user_request):
|
| 23 |
+
prompt = f"Convert this request to a MongoDB query: {user_request}"
|
| 24 |
+
inputs = tokenizer(prompt, return_tensors="pt").to("cuda" if torch.cuda.is_available() else "cpu")
|
| 25 |
+
output = model.generate(**inputs, max_length=150)
|
| 26 |
+
return tokenizer.decode(output[0], skip_special_tokens=True)
|
| 27 |
+
|
| 28 |
+
if __name__ == '__main__':
|
| 29 |
+
app.run(host='0.0.0.0', port=7860)
|
app.py:Zone.Identifier
ADDED
|
File without changes
|
dockerfile
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Use an official lightweight Python image
|
| 2 |
+
FROM python:3.10
|
| 3 |
+
|
| 4 |
+
# Set working directory
|
| 5 |
+
WORKDIR /app
|
| 6 |
+
|
| 7 |
+
# Copy files to container
|
| 8 |
+
COPY app.py requirements.txt /app/
|
| 9 |
+
|
| 10 |
+
# Install dependencies
|
| 11 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 12 |
+
|
| 13 |
+
# Expose port for Flask
|
| 14 |
+
EXPOSE 7860
|
| 15 |
+
|
| 16 |
+
# Run the Flask app
|
| 17 |
+
CMD ["python", "app.py"]
|
dockerfile:Zone.Identifier
ADDED
|
File without changes
|
requirements.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
flask
|
| 2 |
+
torch
|
| 3 |
+
transformers
|
| 4 |
+
accelerate
|
| 5 |
+
sentencepiece
|
| 6 |
+
huggingface_hub
|
requirements.txt:Zone.Identifier
ADDED
|
File without changes
|