Tonic commited on
Commit
0b6ead0
1 Parent(s): 8de78b2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -29
app.py CHANGED
@@ -303,27 +303,6 @@ def query_vectara(text):
303
  return f"Error: {response.status_code}"
304
 
305
 
306
- def convert_to_markdown(vectara_response_json):
307
- vectara_response = json.loads(vectara_response_json)
308
- if vectara_response:
309
- summary = vectara_response.get('summary', 'No summary available')
310
- sources_info = vectara_response.get('sources', [])
311
-
312
- # Format the summary as Markdown
313
- markdown_summary = f' {summary}\n\n'
314
-
315
- # Format the sources as a numbered list
316
- markdown_sources = ""
317
- for i, source_info in enumerate(sources_info):
318
- author = source_info.get('author', 'Unknown author')
319
- title = source_info.get('title', 'Unknown title')
320
- page_number = source_info.get('page number', 'Unknown page number')
321
- markdown_sources += f"{i+1}. {title} by {author}, Page {page_number}\n"
322
-
323
- return f"{markdown_summary}**Sources:**\n{markdown_sources}"
324
- else:
325
- return "No data found in the response."
326
-
327
  # Functions to Wrap the Prompt Correctly
328
  def wrap_text(text, width=90):
329
  lines = text.split('\n')
@@ -425,20 +404,24 @@ def process_and_query(input_language=None, audio_input=None, image_input=None, t
425
  # Use the text to query Vectara
426
  vectara_response_json = query_vectara(combined_text)
427
  print("Vectara Response:", vectara_response_json) # Debug print
428
-
429
- # Convert the Vectara response to Markdown
430
- markdown_output = convert_to_markdown(vectara_response_json)
431
-
432
- # Append the original image description to the markdown output
 
 
 
 
433
  if image_description:
434
- markdown_output += "\n\n**Original Image Description:**\n" + image_description
435
 
436
  # Process the summary with OpenAI
437
- final_response = process_summary_with_stablemed(markdown_output)
438
  print("Final Response:", final_response) # Debug print
439
 
440
  # Evaluate hallucination
441
- hallucination_label = evaluate_hallucination(final_response, markdown_output)
442
  print("Hallucination Label:", hallucination_label) # Debug print
443
  return final_response, hallucination_label
444
  except Exception as e:
 
303
  return f"Error: {response.status_code}"
304
 
305
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
306
  # Functions to Wrap the Prompt Correctly
307
  def wrap_text(text, width=90):
308
  lines = text.split('\n')
 
404
  # Use the text to query Vectara
405
  vectara_response_json = query_vectara(combined_text)
406
  print("Vectara Response:", vectara_response_json) # Debug print
407
+
408
+ # Parse the Vectara response
409
+ vectara_response = json.loads(vectara_response_json)
410
+ summary = vectara_response.get('summary', 'No summary available')
411
+ sources_info = vectara_response.get('sources', [])
412
+ print("Summary:", summary) # Debug print
413
+ print("Sources Info:", sources_info) # Debug print
414
+
415
+ # Append the original image description to the summary
416
  if image_description:
417
+ summary += "\n\n**Original Image Description:**\n" + image_description
418
 
419
  # Process the summary with OpenAI
420
+ final_response = process_summary_with_stablemed(summary)
421
  print("Final Response:", final_response) # Debug print
422
 
423
  # Evaluate hallucination
424
+ hallucination_label = evaluate_hallucination(final_response, summary)
425
  print("Hallucination Label:", hallucination_label) # Debug print
426
  return final_response, hallucination_label
427
  except Exception as e: