adam kovari commited on
Commit
39f98d7
1 Parent(s): 0d1e38c
Files changed (2) hide show
  1. __pycache__/app.cpython-310.pyc +0 -0
  2. app.py +16 -5
__pycache__/app.cpython-310.pyc ADDED
Binary file (1.22 kB). View file
 
app.py CHANGED
@@ -1,15 +1,22 @@
1
  from fastapi import FastAPI
 
2
  from transformers import pipeline
3
-
 
 
 
 
4
  # Create a new FastAPI app instance
5
  app = FastAPI()
6
 
 
 
7
  # Initialize the text generation pipeline
8
  # This function will be able to generate text
9
  # given an input.
10
- pipe = pipeline("text2text-generation",
11
- model="google/flan-t5-small")
12
-
13
  # Define a function to handle the GET request at `/generate`
14
  # The generate() function is defined as a FastAPI route that takes a
15
  # string parameter called text. The function generates text based on the # input using the pipeline() object, and returns a JSON response
@@ -25,4 +32,8 @@ def generate(text: str):
25
  output = pipe(text)
26
 
27
  # Return the generated text in a JSON response
28
- return {"output": output[0]["generated_text"]}
 
 
 
 
 
1
  from fastapi import FastAPI
2
+ from fastapi.responses import RedirectResponse
3
  from transformers import pipeline
4
+ import torch
5
+ from huggingface_hub import hf_hub_download
6
+
7
+ hf_hub_download(repo_id="google/pegasus-xsum", filename="config.json")
8
+
9
  # Create a new FastAPI app instance
10
  app = FastAPI()
11
 
12
+ model_id = "meta-llama/Meta-Llama-3-70B"
13
+
14
  # Initialize the text generation pipeline
15
  # This function will be able to generate text
16
  # given an input.
17
+ pipe = pipeline("text-generation", model=model_id, model_kwargs={"torch_dtype": torch.bfloat16}, device_map="auto")
18
+ #pipe = pipeline("text2text-generation", model="google/flan-t5-small")
19
+
20
  # Define a function to handle the GET request at `/generate`
21
  # The generate() function is defined as a FastAPI route that takes a
22
  # string parameter called text. The function generates text based on the # input using the pipeline() object, and returns a JSON response
 
32
  output = pipe(text)
33
 
34
  # Return the generated text in a JSON response
35
+ return {"output": output[0]["generated_text"]}
36
+
37
+ @app.get("/")
38
+ async def docs_redirect():
39
+ return RedirectResponse(url='/docs')