Overview
In the following article, I introduced a recommendation app for Japan’s Curriculum Guidelines (Gakushu Shido Yoryo) codes.
This time, I introduce how to use the above recommendation app via Gradio’s API.
Usage
Install the library.
pip install gradio_client
For example, let’s use the following data.
| Text | School Type |
|---|---|
| Investigate the mechanisms of air guns, water guns, bottle rockets, etc., and notice that as air is compressed and its volume decreases, the repulsive force increases, but water cannot be compressed. | Elementary School |
Since the JSON data is stored in the second element of the result array, it is retrieved with result[1].
from gradio_client import Client
client = Client("nakamura196/jp-cos")
result = client.predict(
text="空気鉄砲や水鉄砲、ペットボトルロケットなどのしくみを調べ、空気はおし縮められ体積が小さくなるにつれて反発する力が大きくなるが、水はおし縮められないことに気づく。",
courseOfStudy=["小学校"],
api_name="/predict"
)
json_data = result[1]
As a result, the following JSON data is obtained.
[{'dcterms:identifier': '8260243111200000',
'jp-cos:courseOfStudy': '小学校',
'jp-cos:subjectArea': '理科',
'score': 0.215,
'jp-cos:sectionText': '閉じ込めた空気は圧《お》し縮められるが,水は圧《お》し縮められないこと。'},
{'dcterms:identifier': '8260243111100000',
'jp-cos:courseOfStudy': '小学校',
'jp-cos:subjectArea': '理科',
'score': 0.236,
'jp-cos:sectionText': '閉じ込めた空気を圧《お》すと,体積は小さくなるが,圧《お》し返す力は大きくなること。'},
{'dcterms:identifier': '8260243112000000',
'jp-cos:courseOfStudy': '小学校',
'jp-cos:subjectArea': '理科',
'score': 0.246,
'jp-cos:sectionText': '空気と水の性質について追究する中で,既習の内容や生活経験を基に,空気と水の体積や圧《お》し返す力の変化と圧《お》す力との関係について,根拠のある予想や仮説を発想し,表現すること。'},
{'dcterms:identifier': '8260243110000000',
'jp-cos:courseOfStudy': '小学校',
'jp-cos:subjectArea': '理科',
'score': 0.255,
'jp-cos:sectionText': '空気と水の性質 空気と水の性質について,体積や圧《お》し返す力の変化に着目して,それらと圧《お》す力とを関係付けて調べる活動を通して,次の事項を身に付けることができるよう指導する。'}]
Further Reading
More detailed usage can be found by clicking “Use via API” in the footer section.

It provides explanations about parameters and returned values.

Summary
I hope this serves as a useful reference.