adyaprasad commited on
Commit
62eb515
·
verified ·
1 Parent(s): 97d98e2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -14
app.py CHANGED
@@ -1,24 +1,22 @@
1
  from fastapi import FastAPI
2
  from transformers import pipeline
3
 
4
- #creating a new FastAPI app instance
5
- app=FastAPI()
6
 
7
- # calling Hugging Face Model from pipeline
8
- # here I am using, google/flan-t5-small (Text2Text Generating Model)
9
- pipe = pipeline("text2text-generation", model="google/flan-t5-small")
10
 
11
- #creating routes
12
  @app.get("/")
13
  def home():
14
  return {"message": "Your FastAPI and Model is Running"}
15
 
16
- #define a function to handle the GET request at '/generate'
17
- @app.get("/generate")
18
- def generate(text: str):
19
- # use the pipeline to generate text from given input text
20
- output = pipe(text, max_new_tokens=150, temperature=0.3, top_k=30) # Adjust these parameters as per your output accuracy
21
- print(output) # Debugging line
22
- #return the correct key based on model output
23
- return {"output": output[0]['generated_text']}
24
 
 
1
  from fastapi import FastAPI
2
  from transformers import pipeline
3
 
4
+ # Creating a new FastAPI app instance
5
+ app = FastAPI()
6
 
7
+ # Calling the Hugging Face Model from the pipeline
8
+ # Here I am using the Facebook/bart-large-cnn model for summarization
9
+ summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
10
 
11
+ # Creating routes
12
  @app.get("/")
13
  def home():
14
  return {"message": "Your FastAPI and Model is Running"}
15
 
16
+ @app.get("/chat")
17
+ def chat(text: str):
18
+ # Use the summarizer pipeline to generate a summary from the given input text
19
+ output = summarizer(text, max_length=130, min_length=30, do_sample=False)
20
+ # Return the summary from the output
21
+ return {"summary": output[0]['summary_text']}
 
 
22