Spaces:
Running
on
Zero
Running
on
Zero
idan shenfeld
commited on
Commit
·
1ef2970
1
Parent(s):
1aaa40e
upgrade gradio version
Browse files- app/app.py +59 -7
- pyproject.toml +1 -1
app/app.py
CHANGED
@@ -18,7 +18,7 @@ from pandas import DataFrame
|
|
18 |
from transformers import pipeline, AutoTokenizer, AutoModelForCausalLM
|
19 |
|
20 |
|
21 |
-
BASE_MODEL = os.getenv("MODEL", "google/gemma-3-12b-
|
22 |
ZERO_GPU = (
|
23 |
bool(os.getenv("ZERO_GPU", False)) or True
|
24 |
if str(os.getenv("ZERO_GPU")).lower() == "true"
|
@@ -348,8 +348,11 @@ def wrangle_like_data(x: gr.LikeData, history) -> DataFrame:
|
|
348 |
elif x.liked is False:
|
349 |
message["metadata"] = {"title": "disliked"}
|
350 |
|
351 |
-
if
|
|
|
|
|
352 |
message["metadata"] = message["metadata"].__dict__
|
|
|
353 |
rating = message["metadata"].get("title")
|
354 |
if rating == "liked":
|
355 |
message["rating"] = 1
|
@@ -549,10 +552,37 @@ button#add-language-btn {
|
|
549 |
}
|
550 |
"""
|
551 |
|
552 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
553 |
# State variable to track if user has consented
|
554 |
-
user_consented = gr.State(False)
|
555 |
|
|
|
556 |
# Landing page with user agreement
|
557 |
with gr.Group(visible=True) as landing_page:
|
558 |
gr.Markdown("# Welcome to FeeL")
|
@@ -627,7 +657,6 @@ with gr.Blocks(css=css) as demo:
|
|
627 |
chatbot = gr.Chatbot(
|
628 |
elem_id="chatbot",
|
629 |
editable="all",
|
630 |
-
bubble_full_width=False,
|
631 |
value=[
|
632 |
{
|
633 |
"role": "system",
|
@@ -650,15 +679,38 @@ with gr.Blocks(css=css) as demo:
|
|
650 |
|
651 |
submit_btn = gr.Button(value="💾 Submit conversation", visible=False)
|
652 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
653 |
# Function to show main app after consent
|
654 |
def show_main_app():
|
655 |
return gr.Group(visible=False), gr.Group(visible=True), True
|
656 |
|
657 |
-
# Connect consent button to show main app
|
658 |
consent_btn.click(
|
659 |
fn=show_main_app,
|
660 |
inputs=[],
|
661 |
-
outputs=[landing_page, main_app, user_consented]
|
|
|
662 |
)
|
663 |
|
664 |
##############################
|
|
|
18 |
from transformers import pipeline, AutoTokenizer, AutoModelForCausalLM
|
19 |
|
20 |
|
21 |
+
BASE_MODEL = os.getenv("MODEL", "google/gemma-3-12b-pt")
|
22 |
ZERO_GPU = (
|
23 |
bool(os.getenv("ZERO_GPU", False)) or True
|
24 |
if str(os.getenv("ZERO_GPU")).lower() == "true"
|
|
|
348 |
elif x.liked is False:
|
349 |
message["metadata"] = {"title": "disliked"}
|
350 |
|
351 |
+
if message["metadata"] is None:
|
352 |
+
message["metadata"] = {}
|
353 |
+
elif not isinstance(message["metadata"], dict):
|
354 |
message["metadata"] = message["metadata"].__dict__
|
355 |
+
|
356 |
rating = message["metadata"].get("title")
|
357 |
if rating == "liked":
|
358 |
message["rating"] = 1
|
|
|
552 |
}
|
553 |
"""
|
554 |
|
555 |
+
def get_config(request: gr.Request):
|
556 |
+
"""Get configuration from cookies"""
|
557 |
+
config = {"feel_consent": False}
|
558 |
+
if request and 'feel_consent' in request.cookies:
|
559 |
+
config["feel_consent"] = request.cookies['feel_consent'] == 'true'
|
560 |
+
return config["feel_consent"]
|
561 |
+
|
562 |
+
js = '''function js(){
|
563 |
+
window.set_cookie = function(key, value){
|
564 |
+
// Use a longer expiry and more complete cookie setting
|
565 |
+
const d = new Date();
|
566 |
+
d.setTime(d.getTime() + (365*24*60*60*1000));
|
567 |
+
document.cookie = key + "=" + value + ";path=/;expires=" + d.toUTCString() + ";SameSite=Lax";
|
568 |
+
return value === 'true'; // Return boolean directly
|
569 |
+
}
|
570 |
+
|
571 |
+
window.check_cookie = function(key){
|
572 |
+
const value = document.cookie
|
573 |
+
.split('; ')
|
574 |
+
.find(row => row.startsWith(key + '='))
|
575 |
+
?.split('=')[1];
|
576 |
+
return value === 'true'; // Return boolean directly
|
577 |
+
}
|
578 |
+
}'''
|
579 |
+
|
580 |
+
|
581 |
+
|
582 |
+
with gr.Blocks(css=css, js=js) as demo:
|
583 |
# State variable to track if user has consented
|
|
|
584 |
|
585 |
+
user_consented = gr.State(value=False)
|
586 |
# Landing page with user agreement
|
587 |
with gr.Group(visible=True) as landing_page:
|
588 |
gr.Markdown("# Welcome to FeeL")
|
|
|
657 |
chatbot = gr.Chatbot(
|
658 |
elem_id="chatbot",
|
659 |
editable="all",
|
|
|
660 |
value=[
|
661 |
{
|
662 |
"role": "system",
|
|
|
679 |
|
680 |
submit_btn = gr.Button(value="💾 Submit conversation", visible=False)
|
681 |
|
682 |
+
# Check consent on page load
|
683 |
+
demo.load(
|
684 |
+
fn=lambda: None,
|
685 |
+
inputs=None,
|
686 |
+
outputs=None,
|
687 |
+
js="async () => { await new Promise(r => setTimeout(r, 100)); return js(); }"
|
688 |
+
).then(
|
689 |
+
fn=lambda: None,
|
690 |
+
inputs=None,
|
691 |
+
outputs=[user_consented],
|
692 |
+
js="() => { return window.check_cookie('feel_consent'); }"
|
693 |
+
).then(
|
694 |
+
lambda has_consent: (gr.Group(visible=not has_consent), gr.Group(visible=has_consent)),
|
695 |
+
inputs=[user_consented],
|
696 |
+
outputs=[landing_page, main_app]
|
697 |
+
)
|
698 |
+
|
699 |
+
user_consented.change(
|
700 |
+
lambda x: get_config(gr.Request()),
|
701 |
+
inputs=[user_consented],
|
702 |
+
outputs=[landing_page, main_app]
|
703 |
+
)
|
704 |
+
|
705 |
# Function to show main app after consent
|
706 |
def show_main_app():
|
707 |
return gr.Group(visible=False), gr.Group(visible=True), True
|
708 |
|
|
|
709 |
consent_btn.click(
|
710 |
fn=show_main_app,
|
711 |
inputs=[],
|
712 |
+
outputs=[landing_page, main_app, user_consented],
|
713 |
+
js="() => { window.set_cookie('feel_consent', 'true'); return true; }"
|
714 |
)
|
715 |
|
716 |
##############################
|
pyproject.toml
CHANGED
@@ -17,7 +17,7 @@ ml = [
|
|
17 |
"trl>=0.12.2",
|
18 |
]
|
19 |
app = [
|
20 |
-
"gradio>=5.
|
21 |
"huggingface-hub>=0.26.5",
|
22 |
"transformers>=4.47.1",
|
23 |
]
|
|
|
17 |
"trl>=0.12.2",
|
18 |
]
|
19 |
app = [
|
20 |
+
"gradio>=5.23.1",
|
21 |
"huggingface-hub>=0.26.5",
|
22 |
"transformers>=4.47.1",
|
23 |
]
|