Spaces:
Sleeping
Sleeping
File size: 2,053 Bytes
3909b49 a23be62 6eb0b14 a23be62 ea2962f a23be62 ea2962f a23be62 7769f4e |
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 |
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()
|