Update app.py
Browse files
app.py
CHANGED
|
@@ -1,30 +1,15 @@
|
|
| 1 |
-
from fastapi import FastAPI
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
app = FastAPI()
|
| 5 |
-
|
| 6 |
-
def initialize_pipeline():
|
| 7 |
-
return pipeline("text-classification", model="FacebookAI/roberta-large-mnli")
|
| 8 |
|
| 9 |
-
|
|
|
|
| 10 |
|
| 11 |
-
# @app.get("/
|
| 12 |
# def home():
|
| 13 |
-
# return
|
| 14 |
-
|
| 15 |
-
@app.get("/")
|
| 16 |
-
def generate_text(
|
| 17 |
-
text: str = Query(None, description="Input text to generate from"),
|
| 18 |
-
prompt: str = Query(None, description="Optional prompt for fine-tuning the generated text"),
|
| 19 |
-
):
|
| 20 |
-
if not text and not prompt:
|
| 21 |
-
return {"error": "Please provide either 'text' or 'prompt' parameter."}
|
| 22 |
-
|
| 23 |
-
if prompt:
|
| 24 |
-
input_text = f"{text} {prompt}" if text else prompt
|
| 25 |
-
else:
|
| 26 |
-
input_text = text
|
| 27 |
-
|
| 28 |
-
output = pipe(input_text, max_length=100, do_sample=True, top_k=50)
|
| 29 |
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI
|
| 2 |
from transformers import pipeline
|
| 3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
+
app = FastAPI()
|
| 6 |
+
pipe = pipeline("text-classification", model="FacebookAI/roberta-large-mnli")
|
| 7 |
|
| 8 |
+
# @app.get("/")
|
| 9 |
# def home():
|
| 10 |
+
# return{"message":"hello rath"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
+
@app.get("/genrate")
|
| 13 |
+
def gentxt(text : str):
|
| 14 |
+
output = pipe(text)
|
| 15 |
+
return({"output":output[0]["generated_text"]})
|