GurgenGulay commited on
Commit
ebb447c
·
verified ·
1 Parent(s): c094434

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -27
app.py CHANGED
@@ -1,32 +1,36 @@
1
- from fine_tuning import fine_tune_model # Import the function from fine_tuning.py
 
 
 
2
 
3
- def clean_text_with_spacy(text):
4
- # Clean the text using spaCy
5
- doc = nlp(text)
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
- # Function to read prompts.txt file
10
- def read_prompts(file_path):
11
- input_texts = []
12
- target_texts = []
13
- with open(file_path, "r", encoding="utf-8") as file:
14
- lines = file.readlines()
15
- for line in lines:
16
- if line.startswith("input:"):
17
- input_texts.append(line.replace("input:", "").strip())
18
- elif line.startswith("target:"):
19
- target_texts.append(line.replace("target:", "").strip())
20
- return input_texts, target_texts
21
 
22
- # Function to process input texts for fine-tuning
23
- def process_input_for_fine_tuning(input_texts, target_texts):
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
- # Reading data from prompts.txt
29
- input_texts, target_texts = read_prompts("prompts.txt")
 
 
30
 
31
- # Initiating the fine-tuning process
32
- process_input_for_fine_tuning(input_texts, target_texts)
 
 
 
 
 
 
 
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()