InnaV commited on
Commit
bb4617b
·
verified ·
1 Parent(s): 7da29e2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -34
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: #it's import to specify the return type
14
- #Keep this format for the description / args / args description but feel free to modify the tool
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
- topic_words = topic_model.get_topic(topics[0])
28
-
29
- # Retrieve the actual topic words
30
- topic_words = [word[0] for word in topic_words ]
31
- topic_words = ' '.join(topic_words)
32
 
33
- except Exception as e:
34
- return f"Error fetching the topic of the text"
35
-
36
- return "Here is the topic of the text: ", topic_words
37
 
38
  @tool
39
- def get_current_time_in_timezone(timezone: str) -> str:
40
- """A tool that fetches the current local time in a specified timezone.
 
41
  Args:
42
- timezone: A string representing a valid timezone (e.g., 'America/New_York').
 
 
 
43
  """
44
- try:
45
- # Create timezone object
46
- tz = pytz.timezone(timezone)
47
- # Get current time in that timezone
48
- local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
49
- return f"The current local time in {timezone} is: {local_time}"
50
- except Exception as e:
51
- return f"Error fetching time for timezone '{timezone}': {str(e)}"
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()