Spaces:
Sleeping
Sleeping
0.59 Setting scopes
Browse files
app.py
CHANGED
@@ -18,6 +18,8 @@ logging.basicConfig(level=logging.DEBUG)
|
|
18 |
|
19 |
SPACER = '\n' + '*' * 40 + '\n'
|
20 |
|
|
|
|
|
21 |
HF_TOKEN = os.environ.get("HF_TOKEN", None)
|
22 |
login(token=HF_TOKEN)
|
23 |
|
@@ -28,7 +30,7 @@ system_prompts = {
|
|
28 |
"Spanish": "Eres un chatbot servicial que responde a las entradas de los usuarios de forma concisa y original."
|
29 |
}
|
30 |
|
31 |
-
htmL_info = "<center><h1>⚔️ Pharia Bot Battle</h1><p><big>Let the games begin: In this arena, the Pharia 1 model competes against a random challenger.</p><ul><li>Try a prompt in a language you want to explore</li><li>Set the parameters and vote for the best answers</li><li>After casting your vote, both bots reveal their identity</li></big></center>"
|
32 |
|
33 |
model_info = [{"id": "Aleph-Alpha/Pharia-1-LLM-7B-control-hf",
|
34 |
"name": "Pharia 1 LLM 7B control hf"}]
|
@@ -68,6 +70,7 @@ except Exception as e:
|
|
68 |
|
69 |
|
70 |
def get_google_credentials():
|
|
|
71 |
service_account_info = {
|
72 |
"type": "service_account",
|
73 |
"project_id": os.environ.get("GOOGLE_PROJECT_ID"),
|
@@ -81,11 +84,12 @@ def get_google_credentials():
|
|
81 |
"client_x509_cert_url": os.environ.get("GOOGLE_CLIENT_CERT_URL")
|
82 |
}
|
83 |
|
84 |
-
credentials = Credentials.from_service_account_info(service_account_info)
|
85 |
return credentials
|
86 |
|
87 |
|
88 |
def get_google_sheet():
|
|
|
89 |
credentials = get_google_credentials()
|
90 |
client = gspread.authorize(credentials)
|
91 |
sheet = client.open("pharia_bot_battle_logs").sheet1 # Open your Google Sheet
|
@@ -248,7 +252,7 @@ def generate_both(system_prompt, input_text,
|
|
248 |
logging.debug(f'{SPACER}\nOutput row: {sheet_row}')
|
249 |
sheet = get_google_sheet()
|
250 |
sheet.append_row([choice])
|
251 |
-
|
252 |
except Exception as e:
|
253 |
logging.error(f'{SPACER} Error: {e}, Traceback {traceback.format_exc()}')
|
254 |
|
@@ -309,8 +313,6 @@ with gr.Blocks() as demo:
|
|
309 |
with gr.Row(variant="panel"):
|
310 |
better_bot = gr.Radio(["Bot A kicks ass!", "Bot B crushes it!", "It's a draw."], label="Rate the output!")
|
311 |
|
312 |
-
gr.HTML("<p>Inputs, outputs and votes are logged anonymously.</p>")
|
313 |
-
|
314 |
language_dropdown.change(
|
315 |
lambda lang: system_prompts[lang],
|
316 |
inputs=[language_dropdown],
|
|
|
18 |
|
19 |
SPACER = '\n' + '*' * 40 + '\n'
|
20 |
|
21 |
+
SCOPES = ['https://www.googleapis.com/auth/spreadsheets', 'https://www.googleapis.com/auth/drive'] #spread scopes
|
22 |
+
|
23 |
HF_TOKEN = os.environ.get("HF_TOKEN", None)
|
24 |
login(token=HF_TOKEN)
|
25 |
|
|
|
30 |
"Spanish": "Eres un chatbot servicial que responde a las entradas de los usuarios de forma concisa y original."
|
31 |
}
|
32 |
|
33 |
+
htmL_info = "<center><h1>⚔️ Pharia Bot Battle</h1><p><big>Let the games begin: In this arena, the Pharia 1 model competes against a random challenger.</p><ul><li>Try a prompt in a language you want to explore</li><li>Set the parameters and vote for the best answers</li><li>After casting your vote, both bots reveal their identity</li><p>Inputs, outputs and votes are logged anonymously.</p></big></center>"
|
34 |
|
35 |
model_info = [{"id": "Aleph-Alpha/Pharia-1-LLM-7B-control-hf",
|
36 |
"name": "Pharia 1 LLM 7B control hf"}]
|
|
|
70 |
|
71 |
|
72 |
def get_google_credentials():
|
73 |
+
"""Sets credentials for remote sheet"""
|
74 |
service_account_info = {
|
75 |
"type": "service_account",
|
76 |
"project_id": os.environ.get("GOOGLE_PROJECT_ID"),
|
|
|
84 |
"client_x509_cert_url": os.environ.get("GOOGLE_CLIENT_CERT_URL")
|
85 |
}
|
86 |
|
87 |
+
credentials = Credentials.from_service_account_info(service_account_info,scopes=SCOPES)
|
88 |
return credentials
|
89 |
|
90 |
|
91 |
def get_google_sheet():
|
92 |
+
"""Intits auth, gets and returns instance of remote sheet"""
|
93 |
credentials = get_google_credentials()
|
94 |
client = gspread.authorize(credentials)
|
95 |
sheet = client.open("pharia_bot_battle_logs").sheet1 # Open your Google Sheet
|
|
|
252 |
logging.debug(f'{SPACER}\nOutput row: {sheet_row}')
|
253 |
sheet = get_google_sheet()
|
254 |
sheet.append_row([choice])
|
255 |
+
|
256 |
except Exception as e:
|
257 |
logging.error(f'{SPACER} Error: {e}, Traceback {traceback.format_exc()}')
|
258 |
|
|
|
313 |
with gr.Row(variant="panel"):
|
314 |
better_bot = gr.Radio(["Bot A kicks ass!", "Bot B crushes it!", "It's a draw."], label="Rate the output!")
|
315 |
|
|
|
|
|
316 |
language_dropdown.change(
|
317 |
lambda lang: system_prompts[lang],
|
318 |
inputs=[language_dropdown],
|