InnaV commited on
Commit
5b1d670
·
verified ·
1 Parent(s): bb4617b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -5
app.py CHANGED
@@ -9,12 +9,11 @@ from bertopic import BERTopic
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.
@@ -33,14 +32,18 @@ def extract_main_topic(text: str) -> str:
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()
45
 
46
  model = HfApiModel(
 
9
  from Gradio_UI import GradioUI
10
 
11
  @tool
12
+ def my_custom_tool(text: str) -> 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
 
18
  Returns:
19
  str: The processed text output.
 
32
  """
33
  topics, probs = topic_model.transform([text])
34
  topic_id = topics[0]
 
35
 
36
+ if topic_id == -1: # BERTopic assigns -1 to noise (no topic detected)
37
+ return "No clear topic detected."
38
+
39
+ topic_words = topic_model.get_topic(topic_id)
40
+
41
  if topic_words:
42
+ keywords = ", ".join([word for word, _ in topic_words])
43
+ return f"Main Topic Keywords: {keywords}"
44
  else:
45
  return "No topic detected."
46
 
 
47
  final_answer = FinalAnswerTool()
48
 
49
  model = HfApiModel(