GVAmaresh commited on
Commit
8d643c6
·
1 Parent(s): 5187bce

dev check working

Browse files
Files changed (1) hide show
  1. app.py +78 -0
app.py CHANGED
@@ -62,3 +62,81 @@ def Summerized_Text(text):
62
  print(a)
63
  return a[0]['summary_text']
64
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
  print(a)
63
  return a[0]['summary_text']
64
 
65
+ #--------------------------------------------------------------------------------------------------------------------
66
+
67
+ from fastapi.responses import JSONResponse
68
+ from pydantic import BaseModel
69
+ from fastapi import FastAPI
70
+
71
+ class StrRequest(BaseModel):
72
+ text: str
73
+
74
+
75
+ class CompareRequest(BaseModel):
76
+ summary: str
77
+ text: str
78
+
79
+
80
+ @app.get("/api/check")
81
+ def check_connection():
82
+ try:
83
+ return JSONResponse(
84
+ {"status": 200, "message": "Message Successfully Sent"}, status_code=200
85
+ )
86
+ except Exception as e:
87
+ print("Error => ", e)
88
+ return JSONResponse({"status": 500, "message": str(e)}, status_code=500)
89
+
90
+
91
+ @app.post("/api/summerized")
92
+ async def get_summerized(request: StrRequest):
93
+ try:
94
+ print(request)
95
+ text = request.text
96
+ if not text:
97
+ return JSONResponse(
98
+ {"status": 422, "message": "Invalid Input"}, status_code=422
99
+ )
100
+ summary = Summerized_Text(text)
101
+ if "No abstract text." in summary:
102
+ return JSONResponse(
103
+ {"status": 500, "message": "No matching text found", "data": "None"}
104
+ )
105
+
106
+ if not summary:
107
+ return JSONResponse(
108
+ {"status": 500, "message": "No matching text found", "data": {}}
109
+ )
110
+
111
+ return JSONResponse(
112
+ {"status": 200, "message": "Matching text found", "data": summary}
113
+ )
114
+
115
+ except Exception as e:
116
+ print("Error => ", e)
117
+ return JSONResponse({"status": 500, "message": str(e)}, status_code=500)
118
+
119
+
120
+ @app.post("/api/compare")
121
+ def compareTexts(request: CompareRequest):
122
+ try:
123
+ text = request.text
124
+ summary = request.summary
125
+ if not summary or not text:
126
+ return JSONResponse(
127
+ {"status": 422, "message": "Invalid Input"}, status_code=422
128
+ )
129
+ value = compare(text, summary)
130
+ return JSONResponse(
131
+ {
132
+ "status": 200,
133
+ "message": "Comparisons made",
134
+ "value": value,
135
+ "text": text,
136
+ "summary": summary,
137
+ }
138
+ )
139
+ except Exception as e:
140
+ print("Error => ", e)
141
+ return JSONResponse({"status": 500, "message": str(e)}, status_code=500)
142
+