inventwithdean commited on
Commit
0ebe100
·
1 Parent(s): 2eba4c6

fix empty comment post

Browse files
Files changed (1) hide show
  1. app.py +11 -2
app.py CHANGED
@@ -59,6 +59,8 @@ async def retrieve_similar_text_post(query: str) -> str:
59
  try:
60
  if query == "":
61
  raise gr.Error("Query is empty!")
 
 
62
  query_embedding = get_query_embeddings(query)
63
  post = await db.get_text_post_similar(query_embedding)
64
  return post
@@ -78,9 +80,16 @@ async def get_text_post_comments(post_id: int) -> str:
78
 
79
  async def comment_on_text_post(post_id: int, content: str) -> bool:
80
  """Adds a text comment to the text post with id post_id. Returns True if successful"""
 
81
  try:
 
 
 
 
82
  success = await db.comment_on_text_post(post_id, content)
83
  return success
 
 
84
  except Exception as e:
85
  return False
86
 
@@ -117,7 +126,7 @@ with socialnet:
117
  "Retrieve using query, uses semantic search using Vector Similarity"
118
  )
119
  text_input = gr.Textbox(
120
- placeholder="Enter your query", label="Query (Try to be descriptive)"
121
  )
122
  text_output = gr.Textbox(
123
  placeholder="Post will appear here!", label="Output"
@@ -141,7 +150,7 @@ with socialnet:
141
  with gr.TabItem("Post Comment"):
142
  gr.Markdown("Post a comment!")
143
  id_input = gr.Number(label="Post id")
144
- text_input = gr.Textbox(placeholder="Type your comment here", label="Comment")
145
  success = gr.Checkbox(value=False, label="Success")
146
  submit_btn = gr.Button(value="Comment")
147
  submit_btn.click(comment_on_text_post, inputs=[id_input, text_input], outputs=success)
 
59
  try:
60
  if query == "":
61
  raise gr.Error("Query is empty!")
62
+ if len(query) > 1000:
63
+ raise gr.Error("Too Long Query")
64
  query_embedding = get_query_embeddings(query)
65
  post = await db.get_text_post_similar(query_embedding)
66
  return post
 
80
 
81
  async def comment_on_text_post(post_id: int, content: str) -> bool:
82
  """Adds a text comment to the text post with id post_id. Returns True if successful"""
83
+ content = content.strip(" ").strip("\n")
84
  try:
85
+ if content == "":
86
+ raise gr.Error("Content is Empty!")
87
+ if len(content) > 1000:
88
+ raise gr.Error("Too long Comment")
89
  success = await db.comment_on_text_post(post_id, content)
90
  return success
91
+ except gr.Error as e:
92
+ raise e
93
  except Exception as e:
94
  return False
95
 
 
126
  "Retrieve using query, uses semantic search using Vector Similarity"
127
  )
128
  text_input = gr.Textbox(
129
+ placeholder="Enter your query", label="Query (Try to be descriptive)", max_length=500
130
  )
131
  text_output = gr.Textbox(
132
  placeholder="Post will appear here!", label="Output"
 
150
  with gr.TabItem("Post Comment"):
151
  gr.Markdown("Post a comment!")
152
  id_input = gr.Number(label="Post id")
153
+ text_input = gr.Textbox(placeholder="Type your comment here", label="Comment", max_length=1000)
154
  success = gr.Checkbox(value=False, label="Success")
155
  submit_btn = gr.Button(value="Comment")
156
  submit_btn.click(comment_on_text_post, inputs=[id_input, text_input], outputs=success)