Benson commited on
Commit
26099c5
·
1 Parent(s): ec6c205

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -2
app.py CHANGED
@@ -1,13 +1,17 @@
1
  from fastapi import FastAPI
2
  from transformers import pipeline
 
3
 
4
  # Create a new FastAPI app instance
5
  app = FastAPI(docs_url="/")
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", model="google/flan-t5-large",device=0)
11
 
12
  # Define a function to handle the GET request at `/generate`
13
  # The generate() function is defined as a FastAPI route that takes a
@@ -25,4 +29,4 @@ def generate(text: str):
25
  output = pipe(text)
26
  print(output)
27
  # Return the generated text in a JSON response
28
- return {"output": output[0]["generated_text"]}
 
1
  from fastapi import FastAPI
2
  from transformers import pipeline
3
+ import torch
4
 
5
  # Create a new FastAPI app instance
6
  app = FastAPI(docs_url="/")
7
 
8
+ gpu = torch.device("cuda")
9
+
10
+
11
  # Initialize the text generation pipeline
12
  # This function will be able to generate text
13
  # given an input.
14
+ pipe = pipeline("text2text-generation", model="google/flan-t5-small",device=gpu)
15
 
16
  # Define a function to handle the GET request at `/generate`
17
  # The generate() function is defined as a FastAPI route that takes a
 
29
  output = pipe(text)
30
  print(output)
31
  # Return the generated text in a JSON response
32
+ return {"output": output[0]["generated_text"]}