Daniel Fried commited on
Commit
d3c5d0d
1 Parent(s): 2e513e8

remove logging and simplify structure

Browse files
Files changed (3) hide show
  1. modules/app.py → app.py +0 -18
  2. modules/cloud_logging.py +0 -21
  3. start.py +1 -1
modules/app.py → app.py RENAMED
@@ -9,10 +9,6 @@ import pprint
9
  from huggingface_hub import Repository
10
  from text_generation import Client
11
 
12
- import logging
13
- logging.basicConfig(level=logging.INFO)
14
- import modules.cloud_logging
15
-
16
  # from flask import Flask, request, render_template
17
  # from flask_cors import CORS
18
  # app = Flask(__name__, static_folder='static')
@@ -80,8 +76,6 @@ def generate(prefix, suffix=None, temperature=0.9, max_new_tokens=256, top_p=0.9
80
 
81
  if suffix is not None:
82
  prompt = f"{FIM_PREFIX}{prefix}{FIM_SUFFIX}{suffix}{FIM_MIDDLE}"
83
- print("----prompt----")
84
- print(prompt)
85
  else:
86
  prompt = prefix
87
  output = client.generate(prompt, **generate_kwargs)
@@ -117,11 +111,6 @@ async def generate_maybe(info: str):
117
  prompt = form['prompt']
118
  length_limit = int(form['length'])
119
  temperature = float(form['temperature'])
120
- logging.info(json.dumps({
121
- 'length': length_limit,
122
- 'temperature': temperature,
123
- 'prompt': prompt,
124
- }))
125
  try:
126
  generation = generate(prompt, temperature=temperature, max_new_tokens=length_limit, top_p=0.95, repetition_penalty=1.0)
127
  if generation['truncated']:
@@ -131,7 +120,6 @@ async def generate_maybe(info: str):
131
  return {'result': 'success', 'type': 'generate', 'prompt': prompt, 'text': generation['text'], 'message': message}
132
  except Exception as e:
133
  traceback.print_exception(*sys.exc_info())
134
- logging.error(e)
135
  return {'result': 'error', 'type': 'generate', 'prompt': prompt, 'message': f'Error: {e}.'}
136
 
137
  @app.get('/infill')
@@ -147,11 +135,6 @@ async def infill_maybe(info: str):
147
  temperature = float(form['temperature'])
148
  max_retries = 1
149
  extra_sentinel = True
150
- logging.info(json.dumps({
151
- 'length': length_limit,
152
- 'temperature': temperature,
153
- 'parts_joined': '<infill>'.join(form['parts']),
154
- }))
155
  try:
156
  if len(form['parts']) > 2:
157
  return {'result': 'error', 'text': ''.join(form['parts']), 'type': 'infill', 'message': f"error: Only a single infill is supported!"}
@@ -166,7 +149,6 @@ async def infill_maybe(info: str):
166
  # return {'result': 'success', 'prefix': prefix, 'suffix': suffix, 'text': generation['text']}
167
  except Exception as e:
168
  traceback.print_exception(*sys.exc_info())
169
- logging.error(e)
170
  return {'result': 'error', 'type': 'infill', 'message': f'Error: {e}.'}
171
 
172
 
 
9
  from huggingface_hub import Repository
10
  from text_generation import Client
11
 
 
 
 
 
12
  # from flask import Flask, request, render_template
13
  # from flask_cors import CORS
14
  # app = Flask(__name__, static_folder='static')
 
76
 
77
  if suffix is not None:
78
  prompt = f"{FIM_PREFIX}{prefix}{FIM_SUFFIX}{suffix}{FIM_MIDDLE}"
 
 
79
  else:
80
  prompt = prefix
81
  output = client.generate(prompt, **generate_kwargs)
 
111
  prompt = form['prompt']
112
  length_limit = int(form['length'])
113
  temperature = float(form['temperature'])
 
 
 
 
 
114
  try:
115
  generation = generate(prompt, temperature=temperature, max_new_tokens=length_limit, top_p=0.95, repetition_penalty=1.0)
116
  if generation['truncated']:
 
120
  return {'result': 'success', 'type': 'generate', 'prompt': prompt, 'text': generation['text'], 'message': message}
121
  except Exception as e:
122
  traceback.print_exception(*sys.exc_info())
 
123
  return {'result': 'error', 'type': 'generate', 'prompt': prompt, 'message': f'Error: {e}.'}
124
 
125
  @app.get('/infill')
 
135
  temperature = float(form['temperature'])
136
  max_retries = 1
137
  extra_sentinel = True
 
 
 
 
 
138
  try:
139
  if len(form['parts']) > 2:
140
  return {'result': 'error', 'text': ''.join(form['parts']), 'type': 'infill', 'message': f"error: Only a single infill is supported!"}
 
149
  # return {'result': 'success', 'prefix': prefix, 'suffix': suffix, 'text': generation['text']}
150
  except Exception as e:
151
  traceback.print_exception(*sys.exc_info())
 
152
  return {'result': 'error', 'type': 'infill', 'message': f'Error: {e}.'}
153
 
154
 
modules/cloud_logging.py DELETED
@@ -1,21 +0,0 @@
1
- import os
2
- def make_logging_client():
3
- cred_filename = os.environ.get('GOOGLE_APPLICATION_CREDENTIALS')
4
- if not cred_filename:
5
- return None
6
- print("cred filename:", cred_filename)
7
- cred_string = os.environ.get('GOOGLE_APPLICATION_CREDENTIALS_STRING')
8
- print("cred string:", bool(cred_string))
9
- if not os.path.exists(cred_filename):
10
- if cred_string:
11
- print(f"writing cred string to {cred_filename}")
12
- with open(cred_filename, 'w') as f:
13
- f.write(cred_string)
14
- else:
15
- return None
16
- from google.cloud import logging
17
- logging_client = logging.Client()
18
- logging_client.setup_logging()
19
- return logging_client
20
-
21
- logging_client = make_logging_client()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
start.py CHANGED
@@ -1,3 +1,3 @@
1
  import subprocess
2
 
3
- subprocess.run("uvicorn modules.app:app --timeout-keep-alive 300 --host 0.0.0.0 --port 7860", shell=True)
 
1
  import subprocess
2
 
3
+ subprocess.run("uvicorn app:app --timeout-keep-alive 300 --host 0.0.0.0 --port 7860", shell=True)