Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,32 +1,36 @@
|
|
1 |
-
|
|
|
|
|
|
|
2 |
|
3 |
-
def
|
4 |
-
|
5 |
-
|
6 |
-
tokens = [token.lemma_.lower() for token in doc if not token.is_stop and not token.is_punct]
|
7 |
-
return " ".join(tokens)
|
8 |
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
target_texts.append(line.replace("target:", "").strip())
|
20 |
-
return input_texts, target_texts
|
21 |
|
22 |
-
#
|
23 |
-
|
24 |
-
cleaned_input_texts = [clean_text_with_spacy(text) for text in input_texts]
|
25 |
-
cleaned_target_texts = [clean_text_with_spacy(text) for text in target_texts]
|
26 |
-
fine_tune_model(cleaned_input_texts, cleaned_target_texts)
|
27 |
|
28 |
-
|
29 |
-
|
|
|
|
|
30 |
|
31 |
-
|
32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from text_analysis import generate_lesson_from_transcript as generate_lesson_from_transcript_logic
|
3 |
+
from utils import process_large_text
|
4 |
+
from pdfminer.high_level import extract_text # Import PDF-to-text conversion
|
5 |
|
6 |
+
def pdf_to_text(pdf_path):
|
7 |
+
""" Converts PDF to text """
|
8 |
+
return extract_text(pdf_path)
|
|
|
|
|
9 |
|
10 |
+
def generate_lesson(doc_text=None, pdf_file=None):
|
11 |
+
"""
|
12 |
+
Generate lesson from transcript text or PDF input.
|
13 |
+
"""
|
14 |
+
try:
|
15 |
+
if pdf_file:
|
16 |
+
doc_text = pdf_to_text(pdf_file.name)
|
17 |
+
|
18 |
+
# Process large text
|
19 |
+
processed_text = process_large_text(doc_text)
|
|
|
|
|
20 |
|
21 |
+
# Generate lesson
|
22 |
+
generated_text, output_path = generate_lesson_from_transcript_logic(processed_text)
|
|
|
|
|
|
|
23 |
|
24 |
+
if output_path:
|
25 |
+
return generated_text, gr.File(output_path)
|
26 |
+
else:
|
27 |
+
return generated_text, None
|
28 |
|
29 |
+
except Exception as e:
|
30 |
+
return f"Error occurred: {str(e)}", None
|
31 |
+
|
32 |
+
gr.Interface(
|
33 |
+
fn=generate_lesson,
|
34 |
+
inputs=[gr.Textbox(label="Input Text"), gr.File(label="Upload PDF")],
|
35 |
+
outputs=["text", "file"],
|
36 |
+
).launch()
|