Update app.py
Browse files
app.py
CHANGED
@@ -27,27 +27,6 @@ def get_translator(language):
|
|
27 |
return pipeline("translation", model=model_name)
|
28 |
return None
|
29 |
|
30 |
-
# Helper function to generate bullet points
|
31 |
-
def generate_bullet_points(text):
|
32 |
-
print("Original Text:", text)
|
33 |
-
sentences = sent_tokenize(text)
|
34 |
-
print("Sentences:", sentences)
|
35 |
-
|
36 |
-
model = SentenceTransformer('paraphrase-MiniLM-L6-v2')
|
37 |
-
embeddings = model.encode(sentences, convert_to_tensor=True)
|
38 |
-
clusters = util.community_detection(embeddings, threshold=0.75)
|
39 |
-
|
40 |
-
bullet_points = []
|
41 |
-
for cluster in clusters:
|
42 |
-
cluster_sentences = [sentences[idx] for idx in cluster]
|
43 |
-
main_sentence = cluster_sentences[0] if cluster_sentences else ""
|
44 |
-
bullet_points.append(main_sentence.strip())
|
45 |
-
|
46 |
-
result = "\n".join(f"- {point}" for point in bullet_points)
|
47 |
-
print("Bullet Points:", result)
|
48 |
-
|
49 |
-
return result
|
50 |
-
|
51 |
# Helper function to split text into chunks
|
52 |
def split_text(text, max_tokens=1024):
|
53 |
inputs = tokenizer(text, return_tensors='pt', truncation=False)
|
@@ -99,6 +78,20 @@ def process_text(input_text, language):
|
|
99 |
print(f"Translated Text: {translated_text}")
|
100 |
return bullet_points, translated_text
|
101 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
102 |
# Create Gradio interface
|
103 |
iface = gr.Interface(
|
104 |
fn=process_text,
|
@@ -122,3 +115,4 @@ iface.launch()
|
|
122 |
|
123 |
|
124 |
|
|
|
|
27 |
return pipeline("translation", model=model_name)
|
28 |
return None
|
29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
# Helper function to split text into chunks
|
31 |
def split_text(text, max_tokens=1024):
|
32 |
inputs = tokenizer(text, return_tensors='pt', truncation=False)
|
|
|
78 |
print(f"Translated Text: {translated_text}")
|
79 |
return bullet_points, translated_text
|
80 |
|
81 |
+
def generate_bullet_points(text):
|
82 |
+
print("Original Text:", text)
|
83 |
+
sentences = sent_tokenize(text)
|
84 |
+
print("Sentences:", sentences)
|
85 |
+
|
86 |
+
bullet_points = []
|
87 |
+
for sentence in sentences:
|
88 |
+
bullet_points.append(sentence.strip())
|
89 |
+
|
90 |
+
result = "\n".join(f"- {point}" for point in bullet_points)
|
91 |
+
print("Bullet Points:", result)
|
92 |
+
|
93 |
+
return result
|
94 |
+
|
95 |
# Create Gradio interface
|
96 |
iface = gr.Interface(
|
97 |
fn=process_text,
|
|
|
115 |
|
116 |
|
117 |
|
118 |
+
|