js-clarity / app.py
karubiniumu's picture
astradb
bb1fcbd
import gradio as gr
from pipe import pipe
import pytz
import datetime
import json
def run(text):
now = datetime.datetime.now(pytz.timezone('Asia/Tokyo'))
print('\ntext:',text,now)
result = pipe.run({
'retrieve_prompt_builder':{'text':text},
'prompt_builder':{'text':text}
},include_outputs_from=['embedding_retriever','parser'])
for document in result['embedding_retriever']['documents']:
print(document.score,document.id)
print(document.content)
parsed = result['parser']['parsed']
print(parsed)
return json.dumps(parsed,indent=2,ensure_ascii=False)
title = '日本語 明確さ判定'
with gr.Blocks(title=title,css_paths='./app.css') as app:
gr.HTML(f'<h1 class="title">{title}</h1>')
inputs=gr.TextArea(label='テキスト',lines=12)
submit = gr.Button("送信",variant="primary")
reply =gr.JSON(label='回答')
submit.click(lambda: gr.update(interactive=False),inputs=None, outputs=submit) \
.then(fn=run, inputs=inputs, outputs=reply ) \
.then(fn=lambda: gr.update(interactive=True),inputs=None, outputs=submit)
if __name__ == "__main__":
app.launch()