Spaces:
Sleeping
Sleeping
File size: 2,554 Bytes
f2f5171 957c035 f2f5171 957c035 f2f5171 957c035 d95cbea 957c035 f2f5171 d95cbea 957c035 d95cbea 957c035 d95cbea 957c035 d95cbea 957c035 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
import gradio as gr
from fastapi import FastAPI
from app import Summarizer, Request, Result
from app import (
EN_SENTIMENT_MODEL,
EN_SUMMARY_MODEL,
RU_SENTIMENT_MODEL,
RU_SUMMARY_MODEL,
)
from app import DEFAULT_EN_TEXT, DEFAULT_RU_TEXT
app = FastAPI()
pipe = Summarizer()
@app.post("/summ_ru", response_model=Result)
async def ru_summ_api(request: Request):
results = pipe.summarize(request.text, lang="ru")
return results
@app.post("/summ_en", response_model=Result)
async def en_summ_api(request: Request):
results = pipe.summarize(request.text, lang="en")
return results
with gr.Blocks() as demo:
with gr.Row():
with gr.Column(scale=2, min_width=600):
en_sum_description = gr.Markdown(
value=f"Model for Summary: {EN_SUMMARY_MODEL}"
)
en_sent_description = gr.Markdown(
value=f"Model for Sentiment: {EN_SENTIMENT_MODEL}"
)
en_inputs = gr.Textbox(
label="en_input",
lines=5,
value=DEFAULT_EN_TEXT,
placeholder=DEFAULT_EN_TEXT,
)
en_lang = gr.Textbox(value="en", visible=False)
en_outputs = gr.Textbox(
label="en_output",
lines=5,
placeholder="Summary and Sentiment would be here...",
)
en_inbtn = gr.Button("Proceed")
with gr.Column(scale=2, min_width=600):
ru_sum_description = gr.Markdown(
value=f"Model for Summary: {RU_SUMMARY_MODEL}"
)
ru_sent_description = gr.Markdown(
value=f"Model for Sentiment: {RU_SENTIMENT_MODEL}"
)
ru_inputs = gr.Textbox(
label="ru_input",
lines=5,
value=DEFAULT_RU_TEXT,
placeholder=DEFAULT_RU_TEXT,
)
ru_lang = gr.Textbox(value="ru", visible=False)
ru_outputs = gr.Textbox(
label="ru_output",
lines=5,
placeholder="Здесь будет обобщение и эмоциональный окрас текста...",
)
ru_inbtn = gr.Button("Запустить")
en_inbtn.click(
pipe.summ,
[en_inputs, en_lang],
[en_outputs],
)
ru_inbtn.click(
pipe.summ,
[ru_inputs, ru_lang],
[ru_outputs],
)
# mounting at the root path
app = gr.mount_gradio_app(app, demo, path="/")
|