joyinning's picture
Update app.py
ea2962f verified
raw
history blame contribute delete
No virus
2.05 kB
import gradio as gr
from model_utils import load_models, extract_information, predict_tags, extract_4w_qa, generate_why_or_how_question_and_answer
bilstm_model, ner_tokenizer, id2label_ner = load_models()
def extract_and_display_info(user_input):
if user_input:
ner_tags = predict_tags(user_input, bilstm_model, ner_tokenizer, id2label_ner)
extracted_info = extract_4w_qa(user_input, ner_tags)
qa_result = generate_why_or_how_question_and_answer(extracted_info, user_input)
if qa_result:
extracted_info["Generated Question"] = qa_result["question"]
extracted_info["Answer"] = qa_result["answer"]
output_text = "Extracted Information:\n"
for question, answer in extracted_info.items():
output_text += f"- **{question}:** {answer}\n"
return output_text
else:
return "Please enter some text."
iface = gr.Interface(
fn=extract_and_display_info,
inputs=[
gr.Textbox(label="Paste or type your text:", lines=5, placeholder="Enter your text here..."),
],
outputs="text",
title="Information Extraction Chatbot",
description="""
**What is this chatbot about?**
This chatbot is designed to help you extract valuable information from text and engage in deeper conversations about it. It can identify key details, generate insightful questions, and provide informative answers.
**How to use this chatbot:**
1. **Paste or type your text:**
* Please keep the input text to a maximum of 500 words. This ensures optimal performance and response times.
2. **Receive key information:** The chatbot will identify and present essential details like who, what, when, and where.
3. **Explore deeper questions:** Based on the extracted information, the chatbot will generate thought-provoking "why" or "how" questions.
4. **Get concise answers:** The chatbot will then provide relevant answers to these questions, drawing upon the context of your original text.
"""
)
iface.launch()