Spaces:
Sleeping
Sleeping
vtrv.vls
commited on
Commit
·
014ba5e
1
Parent(s):
7307761
s3 functionality
Browse files
app.py
CHANGED
|
@@ -1,20 +1,26 @@
|
|
| 1 |
import gradio
|
| 2 |
import argparse
|
| 3 |
import os
|
|
|
|
|
|
|
| 4 |
|
| 5 |
-
from utils import generate
|
| 6 |
from models import get_tiny_llama, response_tiny_llama
|
| 7 |
from constants import css, js_code, js_light
|
| 8 |
|
| 9 |
MERA_table = None
|
| 10 |
TINY_LLAMA = None
|
| 11 |
|
|
|
|
|
|
|
| 12 |
def giga_gen(content):
|
| 13 |
res = generate(content,'auth_token.json')
|
|
|
|
| 14 |
return res
|
| 15 |
|
| 16 |
def tiny_gen(content):
|
| 17 |
res = response_tiny_llama(TINY_LLAMA, content)
|
|
|
|
| 18 |
return res
|
| 19 |
|
| 20 |
def tab_arena():
|
|
@@ -75,6 +81,18 @@ if __name__ == "__main__":
|
|
| 75 |
# TYPES = ["number", "markdown", "number"]
|
| 76 |
|
| 77 |
TINY_LLAMA = get_tiny_llama()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
demo = build_demo()
|
| 79 |
demo.launch(share=args.share, height=3000, width="110%") # share=args.share
|
| 80 |
|
|
|
|
| 1 |
import gradio
|
| 2 |
import argparse
|
| 3 |
import os
|
| 4 |
+
import boto3
|
| 5 |
+
from datetime import datetime
|
| 6 |
|
| 7 |
+
from utils import generate, send_to_s3
|
| 8 |
from models import get_tiny_llama, response_tiny_llama
|
| 9 |
from constants import css, js_code, js_light
|
| 10 |
|
| 11 |
MERA_table = None
|
| 12 |
TINY_LLAMA = None
|
| 13 |
|
| 14 |
+
S3_SESSION = None
|
| 15 |
+
|
| 16 |
def giga_gen(content):
|
| 17 |
res = generate(content,'auth_token.json')
|
| 18 |
+
send_to_s3(res, f'giga_{str(datetime.now()).replace(" ", "_")}.json', S3_SESSION)
|
| 19 |
return res
|
| 20 |
|
| 21 |
def tiny_gen(content):
|
| 22 |
res = response_tiny_llama(TINY_LLAMA, content)
|
| 23 |
+
send_to_s3(res, f'tiny_{str(datetime.now()).replace(" ", "_")}.json', S3_SESSION)
|
| 24 |
return res
|
| 25 |
|
| 26 |
def tab_arena():
|
|
|
|
| 81 |
# TYPES = ["number", "markdown", "number"]
|
| 82 |
|
| 83 |
TINY_LLAMA = get_tiny_llama()
|
| 84 |
+
|
| 85 |
+
try:
|
| 86 |
+
session = boto3.session.Session()
|
| 87 |
+
S3_SESSION = session.client(
|
| 88 |
+
service_name='s3',
|
| 89 |
+
endpoint_url=os.getenv('S3_ENDPOINT'),
|
| 90 |
+
aws_access_key_id=os.getenv('S3_ENDPOINT'),
|
| 91 |
+
aws_secret_access_key=os.getenv('S3_ENDPOINT'),
|
| 92 |
+
)
|
| 93 |
+
except:
|
| 94 |
+
print('Failed to start s3 session')
|
| 95 |
+
|
| 96 |
demo = build_demo()
|
| 97 |
demo.launch(share=args.share, height=3000, width="110%") # share=args.share
|
| 98 |
|
utils.py
CHANGED
|
@@ -2,6 +2,7 @@ import requests
|
|
| 2 |
import json
|
| 3 |
import os
|
| 4 |
from datetime import datetime, timedelta
|
|
|
|
| 5 |
|
| 6 |
|
| 7 |
def gen_auth_token(auth_file):
|
|
@@ -65,4 +66,8 @@ def generate(content='Привет!', auth_file=None):
|
|
| 65 |
|
| 66 |
resp = get_text(content, auth_token['access_token'])
|
| 67 |
|
| 68 |
-
return resp["choices"][0]["message"]["content"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
import json
|
| 3 |
import os
|
| 4 |
from datetime import datetime, timedelta
|
| 5 |
+
import boto3
|
| 6 |
|
| 7 |
|
| 8 |
def gen_auth_token(auth_file):
|
|
|
|
| 66 |
|
| 67 |
resp = get_text(content, auth_token['access_token'])
|
| 68 |
|
| 69 |
+
return resp["choices"][0]["message"]["content"]
|
| 70 |
+
|
| 71 |
+
def send_to_s3(data, name, session):
|
| 72 |
+
session.put_object(Bucket=os.getenv('S3_BUCKET'), Key=name, Body=json.dumps(data))
|
| 73 |
+
|