SpiceyToad commited on
Commit
7e405ea
Β·
1 Parent(s): 1087336

initial commit

Browse files
Files changed (4) hide show
  1. Dockerfile +12 -60
  2. README.md +30 -7
  3. app.py +24 -0
  4. requirements.txt +4 -0
Dockerfile CHANGED
@@ -1,65 +1,17 @@
1
- FROM zenmldocker/zenml-server:latest
 
2
 
3
- ENV ZENML_ANALYTICS_OPT_IN=true
4
- ENV ZENML_SERVER_DEPLOYMENT_TYPE="hf_spaces"
5
- ENV ZENML_LOGGING_VERBOSITY=DEBUG
6
 
7
- ################################################################################
8
- #
9
- # CONFIGURING YOUR ZENML HF SPACES SERVER
10
- # ---------------------------------------
11
- # By default this space is not persistent. All ZenML metadata is stored in
12
- # localstorage in a SQLite database. If you would like to make your storage
13
- # persistent, use the appropriate environment variables below to configure the
14
- # image to use a MySQL-compatible database service that is reachable from the
15
- # container. See https://docs.zenml.io/getting-started/deploying-zenml/docker
16
- # for more information on how to configure these environment variables.
17
 
18
- # You can also configure the secrets store to use for your ZenML server. Be
19
- # sure to use Huggingface Spaces' 'Repository Secrets' feature to store any
20
- # secrets referenced here. See
21
- # https://huggingface.co/docs/hub/spaces-overview#managing-secrets for more
22
- # information on how to configure these environment variables.
23
 
24
- # ENV ZENML_DEFAULT_PROJECT_NAME=""
25
- # ENV ZENML_DEFAULT_USER_NAME=""
26
- # ENV ZENML_DEFAULT_USER_PASSWORD=""
27
- # ENV ZENML_STORE_URL=""
28
- # ENV ZENML_STORE_SSL_CA=""
29
- # ENV ZENML_STORE_SSL_CERT=""
30
- # ENV ZENML_STORE_SSL_KEY=""
31
- # ENV ZENML_STORE_SSL_VERIFY_SERVER_CERT=""
32
 
33
- # ENV ZENML_LOGGING_VERBOSITY=""
34
-
35
- # # SECRETS STORE CONFIGURATION
36
- # ENV ZENML_SECRETS_STORE_TYPE=""
37
- # ENV ZENML_SECRETS_STORE_ENCRYPTION_KEY=""
38
- # ENV ZENML_SECRETS_STORE_CLASS_PATH=""
39
- # ENV ZENML_JWT_SECRET_KEY=""
40
-
41
- # # AWS Secrets Store Configuration
42
- # ENV ZENML_SECRETS_STORE_REGION_NAME=""
43
- # ENV ZENML_SECRETS_STORE_AWS_ACCESS_KEY_ID=""
44
- # ENV ZENML_SECRETS_STORE_AWS_SECRET_ACCESS_KEY=""
45
- # ENV ZENML_SECRETS_STORE_AWS_SESSION_TOKEN=""
46
- # ENV ZENML_SECRETS_STORE_SECRET_LIST_REFRESH_TIMEOUT=""
47
-
48
- # # GCP Secrets Store Configuration
49
- # ENV ZENML_SECRETS_STORE_PROJECT_ID=""
50
- # ENV GOOGLE_APPLICATION_CREDENTIALS=""
51
-
52
- # # Azure Secrets Store Configuration
53
- # ENV ZENML_SECRETS_STORE_KEY_VAULT_NAME=""
54
- # ENV ZENML_SECRETS_STORE_AZURE_CLIENT_ID=""
55
- # ENV ZENML_SECRETS_STORE_AZURE_CLIENT_SECRET=""
56
- # ENV ZENML_SECRETS_STORE_AZURE_TENANT_ID=""
57
-
58
- # # Hashicorp Secrets Store Configuration
59
- # ENV ZENML_SECRETS_STORE_VAULT_ADDR=""
60
- # ENV ZENML_SECRETS_STORE_VAULT_TOKEN=""
61
- # ENV ZENML_SECRETS_STORE_VAULT_NAMESPACE=""
62
- # ENV ZENML_SECRETS_STORE_MAX_VERSIONS=""
63
-
64
- ENTRYPOINT ["uvicorn", "zenml.zen_server.zen_server_api:app", "--log-level", "debug"]
65
- CMD ["--proxy-headers", "--port", "8080", "--host", "0.0.0.0"]
 
1
+ # Use a lightweight PyTorch image with GPU support
2
+ FROM pytorch/pytorch:2.0.0-cuda11.7-cudnn8-runtime
3
 
4
+ # Set the working directory
5
+ WORKDIR /app
 
6
 
7
+ # Copy the application files into the container
8
+ COPY . /app
 
 
 
 
 
 
 
 
9
 
10
+ # Install required Python dependencies
11
+ RUN pip install --no-cache-dir -r requirements.txt
 
 
 
12
 
13
+ # Expose the FastAPI port
14
+ EXPOSE 7860
 
 
 
 
 
 
15
 
16
+ # Command to run the FastAPI application
17
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
README.md CHANGED
@@ -1,10 +1,33 @@
1
- ---
2
- title: Demo Falc Api
3
- emoji: 🧘
4
- colorFrom: purple
5
  colorTo: green
6
  sdk: docker
7
- pinned: false
8
- app_port: 8080
9
  license: apache-2.0
10
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ title: Falcon 7B FastAPI Service
2
+ emoji: πŸš€
3
+ colorFrom: blue
 
4
  colorTo: green
5
  sdk: docker
6
+ pinned: true
7
+ app_port: 7860
8
  license: apache-2.0
9
+
10
+ # Falcon 7B FastAPI Service
11
+
12
+ This Space hosts a FastAPI application that serves the Falcon 7B model for text generation. The API is deployed using Docker.
13
+
14
+ ## Endpoints
15
+
16
+ ### `/generate`
17
+ **Method**: POST
18
+ **Description**: Generate text from a given prompt.
19
+
20
+ **Payload**:
21
+ ```json
22
+ {
23
+ "prompt": "Your input prompt",
24
+ "max_length": 50
25
+ }
26
+ ```
27
+
28
+ **Response**:
29
+ ```json
30
+ {
31
+ "generated_text": "Generated text from Falcon 7B"
32
+ }
33
+ ```
app.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI, Request
2
+ from transformers import AutoTokenizer, AutoModelForCausalLM
3
+ import torch
4
+
5
+ app = FastAPI()
6
+
7
+ # Load the Falcon 7B model and tokenizer
8
+ MODEL_NAME = "SpiceyToad/demo-falc" # Replace with your Hub repo name
9
+ tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
10
+ model = AutoModelForCausalLM.from_pretrained(MODEL_NAME, torch_dtype=torch.bfloat16, device_map="auto")
11
+
12
+ @app.post("/generate")
13
+ async def generate_text(request: Request):
14
+ # Parse input JSON
15
+ data = await request.json()
16
+ prompt = data.get("prompt", "")
17
+ max_length = data.get("max_length", 50)
18
+
19
+ # Tokenize input and generate text
20
+ inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
21
+ outputs = model.generate(inputs["input_ids"], max_length=max_length)
22
+ response = tokenizer.decode(outputs[0], skip_special_tokens=True)
23
+
24
+ return {"generated_text": response}
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ fastapi
2
+ uvicorn
3
+ torch
4
+ transformers