selamw commited on
Commit
19067cd
·
verified ·
1 Parent(s): 7265096

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -40
app.py CHANGED
@@ -11,61 +11,33 @@ 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
- # 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):
 
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 ":" in input_text:
27
  title, content = map(str.strip, input_text.split(":", 1))
28
  else:
29
  title = input_text
30
  content = ""
31
 
32
+ # Bold the keywords
33
+ for word in bold_words:
34
+ content = content.replace(word, f'\n\n**{word}')
35
+
36
+ # Construct the Markdown output with headings
37
+ formatted_output = f"**{title}**{content}"
38
 
 
 
39
  return formatted_output.strip()
40
+
41
 
42
  @spaces.GPU
43
  def infer_fin_pali(image, question):