Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from spiralfilm import FilmCore, FilmConfig | |
| def greet(name): | |
| return "こんにちは " + name + "さん!! \n僕はパスカルくんだよ。よろしくね" | |
| async def summarize(input_text: str, input_url: str): | |
| if input_text: | |
| _prompt = f""" | |
| 以下の文章を要約してください。 | |
| {input_text} | |
| """ | |
| elif input_url: | |
| url_content = "URLのコンテンツを取得したものを代入します" | |
| _prompt = f""" | |
| 以下の文章を要約してください。 | |
| {url_content} | |
| """ | |
| else: | |
| _prompt = "文章が入力するように促してください。" | |
| config = FilmConfig( | |
| "gpt-3.5-turbo", | |
| api_type="azure", | |
| azure_deployment_id="gpt-35-turbo", | |
| azure_api_version="2023-05-15", | |
| timeout=60.0, # これを入れないとtimeoutが頻繁に発生する | |
| ) | |
| config.get_apikey() | |
| film = FilmCore( | |
| prompt=_prompt, | |
| system_prompt="あなたは優秀なライターです。", | |
| config=config | |
| ) | |
| return await film.run_async() | |
| async def chat(input_text, input_url): | |
| return await summarize(input_text, input_url) | |
| with gr.Blocks() as iface: | |
| # UI | |
| with gr.Row(): | |
| with gr.Column(): | |
| input_text = gr.Textbox(label="") | |
| input_url = gr.Textbox(label="") | |
| chat_btn = gr.Button("Chat") | |
| output_text = gr.Textbox(label="") | |
| # Event handler | |
| chat_btn.click(fn=chat, inputs=[input_text, input_url], outputs=output_text) | |
| if __name__ == "__main__": | |
| iface.launch(auth=("spiralai", "spiralai"), share=True) | |