Spaces:
Running
Running
Commit ·
1b7eda4
1
Parent(s): ad1c460
feat: centralize example inputs
Browse files- app.py +5 -30
- example_inputs.py +29 -0
app.py
CHANGED
|
@@ -15,6 +15,8 @@ import psutil
|
|
| 15 |
import torch
|
| 16 |
from transformers import AutoModel
|
| 17 |
|
|
|
|
|
|
|
| 18 |
|
| 19 |
def _ensure_nltk_punkt_resources() -> None:
|
| 20 |
"""Download punkt resources on first run so inference never fails."""
|
|
@@ -29,13 +31,6 @@ def _ensure_nltk_punkt_resources() -> None:
|
|
| 29 |
DEFAULT_MODEL = "hotchpotch/open-provence-reranker-japanese-xsmall-v1"
|
| 30 |
DEFAULT_THRESHOLD = 0.1
|
| 31 |
DEFAULT_BATCH_SIZE = 8
|
| 32 |
-
DEFAULT_EXAMPLE_QUESTION = "日本の首都はどこですか?"
|
| 33 |
-
DEFAULT_EXAMPLE_CONTEXT = """
|
| 34 |
-
今日は学校に行き、さまざまなことを学んだり、友達と学食でたらふく食べた。
|
| 35 |
-
日本の首都は東京で、東京は日本の政治、経済、文化の中心地らしい。約1,400万人の人口を抱える世界有数の大都市とのことだ。
|
| 36 |
-
夜は飲み会に誘われたが、参加せずに帰宅した、今月そんなにお金が残ってないからなぁ、残念だ。
|
| 37 |
-
""".strip()
|
| 38 |
-
|
| 39 |
MODEL_SCRIPT_ENV = "OPEN_PROVENCE_MODELING_SCRIPT_PATH"
|
| 40 |
|
| 41 |
|
|
@@ -309,30 +304,10 @@ def build_interface() -> gr.Blocks:
|
|
| 309 |
)
|
| 310 |
|
| 311 |
gr.Examples(
|
| 312 |
-
examples=[
|
| 313 |
-
|
| 314 |
-
DEFAULT_EXAMPLE_QUESTION,
|
| 315 |
-
"",
|
| 316 |
-
DEFAULT_EXAMPLE_CONTEXT,
|
| 317 |
-
],
|
| 318 |
-
[
|
| 319 |
-
"What's your favorite Japanese food?",
|
| 320 |
-
"",
|
| 321 |
-
(
|
| 322 |
-
"Work deadlines piled up today, and I kept rambling about budget spreadsheets to my roommate.\n"
|
| 323 |
-
"Next spring I'm planning a trip to Japan so I can wander Kyoto's markets and taste every regional dish I find.\n"
|
| 324 |
-
"Sushi is honestly my favourite—I want to grab a counter seat and let the chef serve endless nigiri until I'm smiling through soy sauce.\n"
|
| 325 |
-
"Later I remembered to water the plants and pay the electricity bill before finally getting some sleep."
|
| 326 |
-
),
|
| 327 |
-
],
|
| 328 |
-
],
|
| 329 |
-
inputs=[
|
| 330 |
-
question_input,
|
| 331 |
-
title_input,
|
| 332 |
-
text_input,
|
| 333 |
-
],
|
| 334 |
label="Sample input",
|
| 335 |
-
examples_per_page=
|
| 336 |
)
|
| 337 |
|
| 338 |
run_button = gr.Button("Run inference", variant="primary")
|
|
|
|
| 15 |
import torch
|
| 16 |
from transformers import AutoModel
|
| 17 |
|
| 18 |
+
from example_inputs import EXAMPLE_INPUTS
|
| 19 |
+
|
| 20 |
|
| 21 |
def _ensure_nltk_punkt_resources() -> None:
|
| 22 |
"""Download punkt resources on first run so inference never fails."""
|
|
|
|
| 31 |
DEFAULT_MODEL = "hotchpotch/open-provence-reranker-japanese-xsmall-v1"
|
| 32 |
DEFAULT_THRESHOLD = 0.1
|
| 33 |
DEFAULT_BATCH_SIZE = 8
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
MODEL_SCRIPT_ENV = "OPEN_PROVENCE_MODELING_SCRIPT_PATH"
|
| 35 |
|
| 36 |
|
|
|
|
| 304 |
)
|
| 305 |
|
| 306 |
gr.Examples(
|
| 307 |
+
examples=[[item.question, item.title, item.text] for item in EXAMPLE_INPUTS],
|
| 308 |
+
inputs=[question_input, title_input, text_input],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 309 |
label="Sample input",
|
| 310 |
+
examples_per_page=len(EXAMPLE_INPUTS),
|
| 311 |
)
|
| 312 |
|
| 313 |
run_button = gr.Button("Run inference", variant="primary")
|
example_inputs.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
from dataclasses import dataclass
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
@dataclass(frozen=True)
|
| 7 |
+
class ExampleInput:
|
| 8 |
+
question: str
|
| 9 |
+
title: str
|
| 10 |
+
text: str
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
EXAMPLE_INPUTS: tuple[ExampleInput, ...] = (
|
| 14 |
+
ExampleInput(
|
| 15 |
+
question="日本の首都はどこですか?",
|
| 16 |
+
title="",
|
| 17 |
+
text="""今日は学校に行き、さまざまなことを学んだり、友達と学食でたらふく食べた。\n日本の首都は東京で、東京は日本の政治、経済、文化の中心地らしい。約1,400万人の人口を抱える世界有数の大都市とのことだ。\n夜は飲み会に誘われたが、参加せずに帰宅した、今月そんなにお金が残ってないからなぁ、残念だ。""",
|
| 18 |
+
),
|
| 19 |
+
ExampleInput(
|
| 20 |
+
question="What's your favorite Japanese food?",
|
| 21 |
+
title="",
|
| 22 |
+
text="""Work deadlines piled up today, and I kept rambling about budget spreadsheets to my roommate.\nNext spring I'm planning a trip to Japan so I can wander Kyoto's markets and taste every regional dish I find.\nSushi is honestly my favourite—I want to grab a counter seat and let the chef serve endless nigiri until I'm smiling through soy sauce.\nLater I remembered to water the plants and pay the electricity bill before finally getting some sleep.""",
|
| 23 |
+
),
|
| 24 |
+
ExampleInput(
|
| 25 |
+
question="この文章の要旨を一言で教えてください。",
|
| 26 |
+
title="",
|
| 27 |
+
text="""新しい研究によると、都市部の公共交通の改善と緑地の拡充は、住民の幸福度を大幅に押し上げる可能性があるという。\n東京や大阪などの大都市では、近年自転車専用レーンや歩行者天国の整備が進み、\n交通事故の発生件数が減少しているだけでなく、観光産業や地域コミュニティの活性化にも寄与している。""",
|
| 28 |
+
),
|
| 29 |
+
)
|