Pranjal12345 commited on
Commit
3fbc02c
1 Parent(s): d3f3a6b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -17
app.py CHANGED
@@ -2,30 +2,19 @@ import gradio as gr
2
  import pandas as pd
3
  import re
4
  import os
5
- import fitz
6
  from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
7
 
8
  tokenizer = AutoTokenizer.from_pretrained("potsawee/t5-large-generation-squad-QuestionAnswer")
9
  model = AutoModelForSeq2SeqLM.from_pretrained("potsawee/t5-large-generation-squad-QuestionAnswer")
10
 
11
- def extract_text_from_pdf(pdf_file_path):
12
- doc = fitz.open(pdf_file_path)
13
- text = ""
14
- for page in doc:
15
- text+=page.get_text()
16
-
17
- return text
18
-
19
- def generate_question_answer_pairs(pdf_file):
20
- if pdf_file is None:
21
- return "Please upload a PDF file"
22
 
23
  d = {'Question':[],'Answer':[]}
24
  df = pd.DataFrame(data=d)
25
 
26
- pdf_text = extract_text_from_pdf(pdf_file.name)
27
-
28
- sentences = re.split(r'(?<=[.!?])', pdf_text)
29
  question_answer_pairs = []
30
 
31
  for sentence in sentences:
@@ -49,13 +38,13 @@ def generate_question_answer_pairs(pdf_file):
49
  return result, "QAPairs.csv"
50
 
51
  title = "Question-Answer Pairs Generation"
52
- input_file = gr.File(label="Upload a PDF file")
53
  output_file = gr.File(label="Download as csv")
54
  output_text = gr.Textbox()
55
 
56
  interface = gr.Interface(
57
  fn=generate_question_answer_pairs,
58
- inputs=input_file,
59
  outputs=[output_text, output_file],
60
  title=title,
61
  )
 
2
  import pandas as pd
3
  import re
4
  import os
 
5
  from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
6
 
7
  tokenizer = AutoTokenizer.from_pretrained("potsawee/t5-large-generation-squad-QuestionAnswer")
8
  model = AutoModelForSeq2SeqLM.from_pretrained("potsawee/t5-large-generation-squad-QuestionAnswer")
9
 
10
+ def generate_question_answer_pairs(input_text):
11
+ if input_text is None:
12
+ return "Please enter a text"
 
 
 
 
 
 
 
 
13
 
14
  d = {'Question':[],'Answer':[]}
15
  df = pd.DataFrame(data=d)
16
 
17
+ sentences = re.split(r'(?<=[.!?])', input_text)
 
 
18
  question_answer_pairs = []
19
 
20
  for sentence in sentences:
 
38
  return result, "QAPairs.csv"
39
 
40
  title = "Question-Answer Pairs Generation"
41
+ input_text = gr.Textbox(lines=4, label="Text:")
42
  output_file = gr.File(label="Download as csv")
43
  output_text = gr.Textbox()
44
 
45
  interface = gr.Interface(
46
  fn=generate_question_answer_pairs,
47
+ inputs=input_text,
48
  outputs=[output_text, output_file],
49
  title=title,
50
  )