Spaces:
Running
Running
Commit
•
69aec0a
1
Parent(s):
a0a2b50
Update app.py
Browse files
app.py
CHANGED
@@ -121,6 +121,20 @@ def toxicityAnalys():
|
|
121 |
return {"status": "pass", "toxicity": predicted_sentiment}
|
122 |
except Exception as e: return {"status": "error", "details": { "error_code": 123, "error_details": str(e).replace("\n", " | ") }} , 400
|
123 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
124 |
if __name__ == "__main__":
|
125 |
config = configFile()
|
126 |
with open(config['config-path'], "w", encoding="utf-8") as outfile:
|
|
|
121 |
return {"status": "pass", "toxicity": predicted_sentiment}
|
122 |
except Exception as e: return {"status": "error", "details": { "error_code": 123, "error_details": str(e).replace("\n", " | ") }} , 400
|
123 |
|
124 |
+
##############
|
125 |
+
# GENERATE TEXT
|
126 |
+
generator = pipeline("text-generation", model="IlyaGusev/rugpt_medium_turbo_instructed")
|
127 |
+
@app.route('/text/api/v1/generate', methods=['POST'])
|
128 |
+
def generateText():
|
129 |
+
try:
|
130 |
+
text = helpers.getFromRequest(request, "text")
|
131 |
+
if not text: return {"status": "error", "details": { "error_code": 101, "error_details": "No text provided" }} , 400
|
132 |
+
result = generator(text, max_length=1024, return_full_text=False, do_sample=bool(randint(0,1)), temperature=float(randint(5,15))/10.0)
|
133 |
+
return {"status": "pass", "result": result[0]["generated_text"]}
|
134 |
+
except Exception as e: return {"status": "error", "details": { "error_code": 123, "error_details": str(e).replace("\n", " | ") }} , 400
|
135 |
+
|
136 |
+
##############
|
137 |
+
# INIT APP
|
138 |
if __name__ == "__main__":
|
139 |
config = configFile()
|
140 |
with open(config['config-path'], "w", encoding="utf-8") as outfile:
|