Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Username field in the flag report is blank #4134

Closed
1 task done
gsachdev-adeptia opened this issue May 9, 2023 · 11 comments · Fixed by #4135
Closed
1 task done

Username field in the flag report is blank #4134

gsachdev-adeptia opened this issue May 9, 2023 · 11 comments · Fixed by #4135
Labels
bug Something isn't working

Comments

@gsachdev-adeptia
Copy link

Describe the bug

The flag log file created from Gradio is having username column but value is empty.

Is there an existing issue for this?

  • I have searched the existing issues

Reproduction

#login function
def same_auth(username, password):
return username == password

#setup gradio interface
iface = gr.Interface(fn=chatbot,
inputs=gr.components.Textbox(lines=7, label="Enter your text"),
outputs="text",
title="testing", allow_flagging="manual",flagging_options=["correct","wrong","ambiguous"])

#launch gradio
iface.launch(share=True ,auth=same_auth)

Screenshot

image

Logs

NA

System Info

Gradio Version 3.29.0,Operation System - Windows 10 Pro, Browser - Chrome  112.0.5615.138

Severity

annoying

@gsachdev-adeptia gsachdev-adeptia added the bug Something isn't working label May 9, 2023
@abidlabs
Copy link
Member

Thanks @gsachdev-adeptia for reporting! This is indeed broken, though we have a fix here: #4135

@gsachdev-adeptia
Copy link
Author

Thanks @abidlabs. Do you know when it will be available for revalidation?

@abidlabs
Copy link
Member

I think we'll merge in main soon (in the next day or so). I'm not sure when we'll release to pypi but you can install gradio from main by following the instructions here: https://gradio.app/docs/main

@abidlabs
Copy link
Member

The fix is on main if you'd like to test it out.

@gsachdev-adeptia
Copy link
Author

gsachdev-adeptia commented May 10, 2023

I uninstall the gradio and installed it from the main branch as you indicated. Still not seeing any value filled in for the username in the flagged file. Do I need to do anything additional to have that written in the flagged file?

@abidlabs
Copy link
Member

abidlabs commented May 10, 2023

I tested with this code and it's working for me on main:

import gradio as gr
#login function
def same_auth(username, password):
    return username == password

#setup gradio interface
iface = gr.Interface(fn=lambda x:x,
    inputs=gr.components.Textbox(lines=7, label="Enter your text"),
    outputs="text",
    title="testing", allow_flagging="manual",flagging_options=["correct","wrong","ambiguous"])

#launch gradio
iface.launch(auth=same_auth)

Can you try it and see if it works for you? You might need to delete the log.csv file

@gsachdev-adeptia
Copy link
Author

gsachdev-adeptia commented May 10, 2023

I am still getting blank user name. Is the below pip to get from main branch correct
pip install https://gradio-main-build.s3.amazonaws.com/2cf13a1c698afed7f4418bc705902fa7868c6890/gradio-3.29.0-py3-none-any.whl

I suspect the above link is not correct.

@abidlabs
Copy link
Member

Please try:

pip install https://gradio-main-build.s3.amazonaws.com/ccdaac1395238eb9c11dacb5710e78de19c1c70e/gradio-3.29.0-py3-none-any.whl

@gsachdev-adeptia
Copy link
Author

It works now. I validated. Thanks for the quick fix.

@RNBharath
Copy link

RNBharath commented Jul 18, 2023

This is not working with Blocks. User Name is still blank.

code to reproduce:


import numpy as np
import gradio as gr

def sepia(input_img, strength):
    sepia_filter = strength * np.array(
        [[0.393, 0.769, 0.189], [0.349, 0.686, 0.168], [0.272, 0.534, 0.131]]
    ) + (1-strength) * np.identity(3)
    sepia_img = input_img.dot(sepia_filter.T)
    sepia_img /= sepia_img.max()
    return sepia_img

callback = gr.CSVLogger()

with gr.Blocks() as demo:
    with gr.Row():
        with gr.Column():
            img_input = gr.Image()
            strength = gr.Slider(0, 1, 0.5)
        img_output = gr.Image()
    with gr.Row():
        btn = gr.Button("Flag")
        
    # This needs to be called at some point prior to the first call to callback.flag()
    callback.setup([img_input, strength, img_output], "flagged_data_points")

    img_input.change(sepia, [img_input, strength], img_output)
    strength.change(sepia, [img_input, strength], img_output)
    
    # We can choose which components to flag -- in this case, we'll flag all of them
    btn.click(lambda *args: callback.flag(args), [img_input, strength, img_output], None, preprocess=False)

demo.launch()

Gradio version: gradio-3.37.0

Can someone please help.
Basically we need to capture the user accessing the app in backend db.

@spaceman-cb
Copy link

@RNBharath One year later, I suspect you've already sorted this out, but I was running into a similar problem today.

For anyone encountering this problem in the future, it looks like you need to explicitly pass the username/request to CSVLogger, similar to the code below:

flagger = gr.CSVLogger()

def flag(
    component_field_1,
    component_field_2,
    request: gr.Request  # <-- IMPORTANT
):
    flagger.flag(
        [component_field_1, component_field_2], 
        username=request.username  # <-- IMPORTANT
)

with gr.Blocks() as demo:

    # UI goes here

    flagger.setup( # components # )
    component_1.click(
        flag,    # <-- IMPORTANT
        # components go here
    )

@abidlabs, when following the documentation for the first time, it's very easy to just copy & paste btn.click(lambda *args: callback.flag(list(args)) ... from the example code at the bottom without realizing the need to pass the username as well. Explaining this there may save future developers some trouble.

Hope this helps!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants