File size: 1,158 Bytes
7e9cf5a
b354cf3
7e9cf5a
 
219dfe0
 
7e9cf5a
219dfe0
 
 
 
7e9cf5a
 
 
 
 
219dfe0
7e9cf5a
73dce56
 
 
 
 
 
 
 
 
 
 
 
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
39
40
41
42
43
44
import gradio as gr
import requests
import re

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)  

    for sentence in sentences:
        if sentence.strip():
            output = query({
                "inputs": sentence,
            })
            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()