Vishwas1 commited on
Commit
5e90465
1 Parent(s): f27eb36

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -15
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
- url = "http://34.122.217.42/complete_batch"
12
- data = {
13
- "debug_ext_path": "foo",
14
- "context":prompt,
15
  "top_p": 0.9,
16
  "temp": 0.75}
17
  try:
18
- response = requests.post(url, json=data)
19
- if response.status_code == 200:
20
- data_str=response.json()
21
- slack_msg="Supplied Prompt was :"+data["context"]+"\n\n"
22
- slack_msg = slack_msg+"Response receievd was : \n\n"
23
- for i in range(4):
24
- slack_msg = slack_msg+data_str["completions"][i]["completion"]+"\n\n"
25
- slack_msg = slack_msg+data_str["completions"][i]["log_prob"]+"\n\n"
26
- else:
27
- slack_msg="Failed to send JSON message to URL"
 
 
 
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(