Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,24 +7,32 @@ import flask
|
|
| 7 |
import requests
|
| 8 |
import json
|
| 9 |
app = flask.Flask(__name__, template_folder="static")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
def text_generate(prompt):
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
"top_p": 0.9,
|
| 16 |
"temp": 0.75}
|
| 17 |
try:
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
| 28 |
except requests.exceptions.Timeout:
|
| 29 |
slack_msg="Failed to send JSON message to URL due to timeout error"
|
| 30 |
pass
|
|
@@ -73,7 +81,7 @@ def handle_event():
|
|
| 73 |
channel= SLACK_CHANNEL
|
| 74 |
conversation = request.json['event'] ['text']
|
| 75 |
print(conversation)
|
| 76 |
-
response=text_generate(conversation)
|
| 77 |
# Post the response back to the Slack channel
|
| 78 |
try:
|
| 79 |
client.chat_postMessage(
|
|
|
|
| 7 |
import requests
|
| 8 |
import json
|
| 9 |
app = flask.Flask(__name__, template_folder="static")
|
| 10 |
+
|
| 11 |
+
#API_URL = "http://34.122.217.42/complete_batch"
|
| 12 |
+
API_URL = "https://api-inference.huggingface.co/models/Salesforce/codegen-350M-multi"
|
| 13 |
+
API_TOKEN = os.environ["API_TOKEN"]
|
| 14 |
+
headers = {"Authorization": f"Bearer {API_TOKEN}"}
|
| 15 |
def text_generate(prompt):
|
| 16 |
+
#Prints to debug the code
|
| 17 |
+
print(f"*****Inside text_generate - Prompt is :{prompt}")
|
| 18 |
+
|
| 19 |
+
data ={"inputs":prompt,
|
| 20 |
"top_p": 0.9,
|
| 21 |
"temp": 0.75}
|
| 22 |
try:
|
| 23 |
+
response = requests.post(API_URL, headers=headers, json=data)
|
| 24 |
+
if response.status_code == 200:
|
| 25 |
+
data_str=response.json()
|
| 26 |
+
slack_msg="Supplied Prompt was :"+data["context"]+"\n\n"
|
| 27 |
+
slack_msg = slack_msg+"Response receievd was : \n\n"
|
| 28 |
+
'''
|
| 29 |
+
for i in range(4):
|
| 30 |
+
slack_msg = slack_msg+data_str["completions"][i]["completion"]+"\n\n"
|
| 31 |
+
slack_msg = slack_msg+data_str["completions"][i]["log_prob"]+"\n\n"
|
| 32 |
+
'''
|
| 33 |
+
slack_msg=slack_msg+data_str
|
| 34 |
+
else:
|
| 35 |
+
slack_msg="Failed to send JSON message to URL"
|
| 36 |
except requests.exceptions.Timeout:
|
| 37 |
slack_msg="Failed to send JSON message to URL due to timeout error"
|
| 38 |
pass
|
|
|
|
| 81 |
channel= SLACK_CHANNEL
|
| 82 |
conversation = request.json['event'] ['text']
|
| 83 |
print(conversation)
|
| 84 |
+
response=text_generate(conversation[15:])
|
| 85 |
# Post the response back to the Slack channel
|
| 86 |
try:
|
| 87 |
client.chat_postMessage(
|