fixing issue #3178 (#3227)

* Update interface.py

 if the first param is self, trim the param list

* Update CHANGELOG.md

* update and add test

* update and add test

---------

Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
Co-authored-by: Freddy Boulton <alfonsoboulton@gmail.com>
This commit is contained in:
or25 2023-03-06 21:27:47 +02:00 committed by GitHub
parent 9fb3c2236d
commit 75a1adee93
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 2 deletions

View File

@ -30,6 +30,7 @@ No changes to highlight.
## Bug Fixes: ## Bug Fixes:
- Ensure uploaded images are always shown in the sketch tool by [@pngwn](https://github.com/pngwn) in [PR 3386](https://github.com/gradio-app/gradio/pull/3386) - Ensure uploaded images are always shown in the sketch tool by [@pngwn](https://github.com/pngwn) in [PR 3386](https://github.com/gradio-app/gradio/pull/3386)
- Fixes bug where when if fn is a non-static class member, then self should be ignored as the first param of the fn by [@or25](https://github.com/or25) in [PR #3227](https://github.com/gradio-app/gradio/pull/3227)
## Documentation Changes: ## Documentation Changes:
No changes to highlight. No changes to highlight.
@ -309,8 +310,8 @@ By [@maxaudron](https://github.com/maxaudron) in [PR 3075](https://github.com/gr
- Fixes bug where interactive output image cannot be set when in edit mode by [@dawoodkhan82](https://github.com/@dawoodkhan82) in [PR 3135](https://github.com/gradio-app/gradio/pull/3135) - Fixes bug where interactive output image cannot be set when in edit mode by [@dawoodkhan82](https://github.com/@dawoodkhan82) in [PR 3135](https://github.com/gradio-app/gradio/pull/3135)
- A share link will automatically be created when running on Sagemaker notebooks so that the front-end is properly displayed by [@abidlabs](https://github.com/abidlabs) in [PR 3137](https://github.com/gradio-app/gradio/pull/3137) - A share link will automatically be created when running on Sagemaker notebooks so that the front-end is properly displayed by [@abidlabs](https://github.com/abidlabs) in [PR 3137](https://github.com/gradio-app/gradio/pull/3137)
- Fixes a few dropdown component issues; hide checkmark next to options as expected, and keyboard hover is visible by [@dawoodkhan82](https://github.com/dawoodkhan82) in [PR 3145]https://github.com/gradio-app/gradio/pull/3145) - Fixes a few dropdown component issues; hide checkmark next to options as expected, and keyboard hover is visible by [@dawoodkhan82](https://github.com/dawoodkhan82) in [PR 3145]https://github.com/gradio-app/gradio/pull/3145)
- Fixed bug where example pagination buttons were not visible in dark mode or displayed under the examples table. By [@freddyaboulton](https://github.com/freddyaboulton) in [PR 3144](https://github.com/gradio-app/gradio/pull/3144) - Fixed bug where example pagination buttons were not visible in dark mode or displayed under the examples table. By [@freddyaboulton](https://github.com/freddyaboulton) in [PR 3144](https://github.com/gradio-app/gradio/pull/3144)
- Fixed bug where the font color of axis labels and titles for native plots did not respond to dark mode preferences. By [@freddyaboulton](https://github.com/freddyaboulton) in [PR 3146](https://github.com/gradio-app/gradio/pull/3146) - Fixed bug where the font color of axis labels and titles for native plots did not respond to dark mode preferences. By [@freddyaboulton](https://github.com/freddyaboulton) in [PR 3146](https://github.com/gradio-app/gradio/pull/3146)
## Documentation Changes: ## Documentation Changes:
- Added a guide on the 4 kinds of Gradio Interfaces by [@yvrjsharma](https://github.com/yvrjsharma) and [@abidlabs](https://github.com/abidlabs) in [PR 3003](https://github.com/gradio-app/gradio/pull/3003) - Added a guide on the 4 kinds of Gradio Interfaces by [@yvrjsharma](https://github.com/yvrjsharma) and [@abidlabs](https://github.com/abidlabs) in [PR 3003](https://github.com/gradio-app/gradio/pull/3003)

View File

@ -400,6 +400,8 @@ class Interface(Blocks):
Interface.instances.add(self) Interface.instances.add(self)
param_names = inspect.getfullargspec(self.fn)[0] param_names = inspect.getfullargspec(self.fn)[0]
if len(param_names) > 0 and inspect.ismethod(self.fn):
param_names = param_names[1:]
for component, param_name in zip(self.input_components, param_names): for component, param_name in zip(self.input_components, param_names):
assert isinstance(component, IOComponent) assert isinstance(component, IOComponent)
if component.label is None: if component.label is None:

View File

@ -13,6 +13,7 @@ from fastapi.testclient import TestClient
import gradio import gradio
from gradio.blocks import Blocks from gradio.blocks import Blocks
from gradio.components import Image, Textbox
from gradio.interface import Interface, TabbedInterface, close_all, os from gradio.interface import Interface, TabbedInterface, close_all, os
from gradio.layouts import TabItem, Tabs from gradio.layouts import TabItem, Tabs
from gradio.utils import assert_configs_are_equivalent_besides_ids from gradio.utils import assert_configs_are_equivalent_besides_ids
@ -59,6 +60,24 @@ class TestInterface:
demo = Interface(fn=greet_upper_case, inputs="text", outputs="text") demo = Interface(fn=greet_upper_case, inputs="text", outputs="text")
assert demo("abubakar") == "Hello Abubakar!" assert demo("abubakar") == "Hello Abubakar!"
def test_input_labels_extracted_from_method(self):
class A:
def test(self, parameter_name):
return parameter_name
t = Textbox()
Interface(A().test, t, "text")
assert t.label == "parameter_name"
def test(parameter_name1, parameter_name2):
return parameter_name1
t = Textbox()
i = Image()
Interface(test, [t, i], "text")
assert t.label == "parameter_name1"
assert i.label == "parameter_name2"
def test_examples_valid_path(self): def test_examples_valid_path(self):
path = os.path.join( path = os.path.join(
os.path.dirname(__file__), "../gradio/test_data/flagged_with_log" os.path.dirname(__file__), "../gradio/test_data/flagged_with_log"