mdasad3617 commited on
Commit
3f9545b
·
verified ·
1 Parent(s): ad77dee

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -92
app.py DELETED
@@ -1,92 +0,0 @@
1
- import gradio as gr
2
- import logging
3
- from transformers import pipeline
4
- from services.text_input_handler import handle_text_input
5
- from services.file_input_handler import read_text_file, read_pdf_file, read_docx_file
6
- from services.audio_input_handler import audio_to_text
7
- from utils.logging_utils import setup_logging
8
-
9
- class TextSummarizer:
10
- def __init__(self, model_name="t5-small"):
11
- self.summarizer = pipeline("summarization", model=model_name)
12
-
13
- def summarize(self, text):
14
- if not text:
15
- return "No text to summarize."
16
- summary = self.summarizer(text, max_length=150, min_length=30, do_sample=False)
17
- return summary[0]['summary_text']
18
-
19
- def process_input(input_type, input_data):
20
- try:
21
- logging.info(f"Processing input type: {input_type}")
22
-
23
- if input_type == "Text":
24
- processed_text = handle_text_input(input_data)
25
- elif input_type == "Text File":
26
- processed_text = read_text_file(input_data)
27
- elif input_type == "PDF":
28
- processed_text = read_pdf_file(input_data)
29
- elif input_type == "DOCX":
30
- processed_text = read_docx_file(input_data)
31
- elif input_type == "Audio":
32
- processed_text = audio_to_text(input_data)
33
- else:
34
- return "Invalid input type."
35
-
36
- if processed_text:
37
- summary = summarizer.summarize(processed_text)
38
- logging.info(f"{input_type} processed successfully.")
39
- return summary
40
- else:
41
- logging.error(f"Failed to process {input_type}.")
42
- return "Failed to process the input. Check logs for more details."
43
- except Exception as e:
44
- logging.error(f"Error during summarization: {e}")
45
- return "An error occurred during summarization. Please check the logs for more details."
46
-
47
- def main():
48
- # Setup logging
49
- setup_logging()
50
- logging.info("Starting GenAI Lab Report Analyzer with Gradio.")
51
-
52
- # Initialize summarizer
53
- global summarizer
54
- summarizer = TextSummarizer()
55
-
56
- # Gradio interface
57
- input_type = gr.inputs.Radio(choices=["Text", "Text File", "PDF", "DOCX", "Audio"], label="Select Input Type")
58
- input_data = gr.inputs.Textbox(lines=5, label="Enter your text here") # Default for text input
59
-
60
- def update_input_type(input_type):
61
- if input_type == "Text":
62
- return gr.update(value="", placeholder="Type your text here...")
63
- elif input_type == "Text File":
64
- return gr.update(value=None, type="file", label="Upload your text file")
65
- elif input_type == "PDF":
66
- return gr.update(value=None, type="file", label="Upload your PDF file")
67
- elif input_type == "DOCX":
68
- return gr.update(value=None, type="file", label="Upload your DOCX file")
69
- elif input_type == "Audio":
70
- return gr.update(value=None, type="file", label="Upload your audio file")
71
- else:
72
- return gr.update(value="", placeholder="Invalid input type")
73
-
74
- input_data = gr.inputs.Textbox(lines=5, label="Enter your text here") # Default for text input
75
- output = gr.outputs.Textbox(label="Report Result")
76
-
77
- interface = gr.Interface(
78
- fn=process_input,
79
- inputs=[input_type, input_data],
80
- outputs=output,
81
- title="GenAI Lab Report Analyzer",
82
- description="Upload a file, record audio, or type text to generate a summary. Select the appropriate input type and provide the input.",
83
- live=True,
84
- theme="default",
85
- layout="vertical",
86
- allow_flagging="never"
87
- )
88
-
89
- interface.launch()
90
-
91
- if __name__ == "__main__":
92
- main()