selamw commited on
Commit
aeaeda9
·
verified ·
1 Parent(s): 63a76b3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -13
app.py CHANGED
@@ -11,28 +11,62 @@ model_id = "selamw/BirdWatcher"
11
  bnb_config = BitsAndBytesConfig(load_in_8bit=True)
12
 
13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  def convert_to_markdown(input_text):
15
- """Converts bird information text to Markdown format,
16
- making specific keywords bold and adding headings.
 
 
17
  Args:
18
  input_text (str): The input text containing bird information.
 
19
  Returns:
20
  str: The formatted Markdown text.
21
  """
22
-
23
- bold_words = ['Look:', 'Cool Fact!:', 'Habitat:', 'Food:', 'Birdie Behaviors:']
24
-
25
- # Split into title and content based on the first ":", handling extra whitespace
26
- title, content = map(str.strip, input_text.split(":", 1))
27
- # Bold the keywords
 
 
 
 
 
28
  for word in bold_words:
29
- content = content.replace(word, f'\n\n**{word}')
30
-
31
- # Construct the Markdown output with headings
32
- formatted_output = f"**{title}**{content}"
33
 
 
 
34
  return formatted_output.strip()
35
-
36
  @spaces.GPU
37
  def infer_fin_pali(image, question):
38
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
 
11
  bnb_config = BitsAndBytesConfig(load_in_8bit=True)
12
 
13
 
14
+ # def convert_to_markdown(input_text):
15
+ # """Converts bird information text to Markdown format,
16
+ # making specific keywords bold and adding headings.
17
+ # Args:
18
+ # input_text (str): The input text containing bird information.
19
+ # Returns:
20
+ # str: The formatted Markdown text.
21
+ # """
22
+
23
+ # bold_words = ['Look:', 'Cool Fact!:', 'Habitat:', 'Food:', 'Birdie Behaviors:']
24
+
25
+ # # Split into title and content based on the first ":", handling extra whitespace
26
+ # if len(input_text.split(":", 1)) > 1:
27
+ # title, content = map(str.strip, input_text.split(":", 1))
28
+
29
+ # # Bold the keywords
30
+ # for word in bold_words:
31
+ # content = content.replace(word, f'\n\n**{word}')
32
+
33
+ # # Construct the Markdown output with headings
34
+ # formatted_output = f"**{title}**{content}"
35
+ # else:
36
+ # formatted_output = input_text
37
+ # return formatted_output.strip()
38
+
39
+ import re
40
+
41
  def convert_to_markdown(input_text):
42
+ """
43
+ Converts bird information text to Markdown format,
44
+ making specific keywords bold and adding headings.
45
+
46
  Args:
47
  input_text (str): The input text containing bird information.
48
+
49
  Returns:
50
  str: The formatted Markdown text.
51
  """
52
+
53
+ bold_words = ['look:', 'cool fact!:', 'habitat:', 'food:', 'birdie behaviors:']
54
+
55
+ # Split into title and content, handle missing ":"
56
+ if ":" in input_text:
57
+ title, content = map(str.strip, input_text.split(":", 1))
58
+ else:
59
+ title = input_text
60
+ content = ""
61
+
62
+ # Bold the keywords (case-insensitive, word boundaries)
63
  for word in bold_words:
64
+ content = re.sub(rf"\b({word.lower()})\b", r"**\1**", content.lower())
 
 
 
65
 
66
+ # Construct Markdown output
67
+ formatted_output = f"**{title}**\n{content}"
68
  return formatted_output.strip()
69
+
70
  @spaces.GPU
71
  def infer_fin_pali(image, question):
72
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")