Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,47 +8,37 @@ from bertopic import BERTopic
|
|
| 8 |
|
| 9 |
from Gradio_UI import GradioUI
|
| 10 |
|
| 11 |
-
|
| 12 |
@tool
|
| 13 |
-
def my_custom_tool(text:str, arg2:int)-> str:
|
| 14 |
-
|
| 15 |
-
"""A tool that does nothing yet
|
| 16 |
-
Args:
|
| 17 |
-
arg1: the first argument
|
| 18 |
-
arg2: the second argument
|
| 19 |
-
"""
|
| 20 |
-
try:
|
| 21 |
-
# Load the pre-trained BERTopic model
|
| 22 |
-
topic_model = BERTopic.load("MaartenGr/BERTopic_ArXiv")
|
| 23 |
-
|
| 24 |
-
# Generate topics and their probabilities
|
| 25 |
-
topics, _ = topic_model.transform(text)
|
| 26 |
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
topic_words = [word[0] for word in topic_words ]
|
| 31 |
-
topic_words = ' '.join(topic_words)
|
| 32 |
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
return "
|
| 37 |
|
| 38 |
@tool
|
| 39 |
-
def
|
| 40 |
-
"""
|
|
|
|
| 41 |
Args:
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
| 43 |
"""
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
return f"
|
| 50 |
-
|
| 51 |
-
return
|
| 52 |
|
| 53 |
|
| 54 |
final_answer = FinalAnswerTool()
|
|
|
|
| 8 |
|
| 9 |
from Gradio_UI import GradioUI
|
| 10 |
|
|
|
|
| 11 |
@tool
|
| 12 |
+
def my_custom_tool(text: str, arg2: int) -> str:
|
| 13 |
+
"""A tool that processes input text and returns a modified version.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
+
Args:
|
| 16 |
+
text (str): The input text to process.
|
| 17 |
+
arg2 (int): An integer parameter for additional processing.
|
|
|
|
|
|
|
| 18 |
|
| 19 |
+
Returns:
|
| 20 |
+
str: The processed text output.
|
| 21 |
+
"""
|
| 22 |
+
return f"Processed text: {text}"
|
| 23 |
|
| 24 |
@tool
|
| 25 |
+
def extract_main_topic(text: str) -> str:
|
| 26 |
+
"""Extracts the main topic from a given text using BERTopic.
|
| 27 |
+
|
| 28 |
Args:
|
| 29 |
+
text (str): The input text to analyze.
|
| 30 |
+
|
| 31 |
+
Returns:
|
| 32 |
+
str: The extracted main topic as keywords.
|
| 33 |
"""
|
| 34 |
+
topics, probs = topic_model.transform([text])
|
| 35 |
+
topic_id = topics[0]
|
| 36 |
+
topic_words = topic_model.get_topic(topic_id)
|
| 37 |
+
|
| 38 |
+
if topic_words:
|
| 39 |
+
return f"Main Topic: {topic_words}"
|
| 40 |
+
else:
|
| 41 |
+
return "No topic detected."
|
| 42 |
|
| 43 |
|
| 44 |
final_answer = FinalAnswerTool()
|