File size: 986 Bytes
7e9cf5a
 
 
 
 
219dfe0
 
7e9cf5a
219dfe0
 
 
 
7e9cf5a
 
 
 
 
219dfe0
7e9cf5a
219dfe0
 
 
 
 
7e9cf5a
219dfe0
7e9cf5a
 
 
 
 
 
 
 
219dfe0
7e9cf5a
 
 
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
import gradio as gr
import pandas as pd
import re
import os

API_URL = "https://api-inference.huggingface.co/models/potsawee/t5-large-generation-squad-QuestionAnswer"
headers = {"Authorization": "Bearer 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"}

def query(payload):
	response = requests.post(API_URL, headers=headers, json=payload)
	return response.json()
    
def generate_question_answer_pairs(input_text):
    if input_text is None:
        return "Please enter a text"

    sentences = re.split(r'(?<=[.!?])', input_text)
    outputs = [] 

    for i in range(len(sentences)):
        output = query({
            "inputs": sentences[i],
        })
        outputs.append(output)  
            
    return outputs

title = "Question-Answer Pairs Generation"
input_text = gr.Textbox(lines=4, label="Text:")
output_text = gr.Textbox()

interface = gr.Interface(
    fn=generate_question_answer_pairs,
    inputs=input_text,
    outputs=output_text,
    title=title,
)
interface.launch()