vonewman commited on
Commit
7a9421c
1 Parent(s): 66bf218

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -17
app.py CHANGED
@@ -1,27 +1,20 @@
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", model="google/flan-t5-small")
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
14
- # string parameter called text. The function generates text based on the # input using the pipeline() object, and returns a JSON response
15
- # containing the generated text under the key "output"
16
  @app.get("/generate")
17
  def generate(text: str):
18
  """
19
  Using the text2text-generation pipeline from `transformers`, generate text
20
  from the given input text. The model used is `google/flan-t5-small`, which
21
- can be found [here](<https://huggingface.co/google/flan-t5-small>).
22
  """
23
- # Use the pipeline to generate text from the given input text
24
  output = pipe(text)
25
-
26
- # Return the generated text in a JSON response
27
  return {"output": output[0]["generated_text"]}
 
1
  from fastapi import FastAPI
2
  from transformers import pipeline
3
+
4
+
5
+ # NOTE - we configure docs_url to serve the interactive Docs at the root path
6
+ # of the app. This way, we can use the docs as a landing page for the app on Spaces.
7
+ app = FastAPI(docs_url="/")
8
+
9
+ pipe = pipeline("text2text-generation", model="google/flan-t5-small")
10
+
11
+
 
 
 
 
12
  @app.get("/generate")
13
  def generate(text: str):
14
  """
15
  Using the text2text-generation pipeline from `transformers`, generate text
16
  from the given input text. The model used is `google/flan-t5-small`, which
17
+ can be found [here](https://huggingface.co/google/flan-t5-small).
18
  """
 
19
  output = pipe(text)
 
 
20
  return {"output": output[0]["generated_text"]}