not-lain commited on
Commit
a31fde9
1 Parent(s): 463110e

added integration for the hallucination model

Browse files
Files changed (1) hide show
  1. app.py +18 -0
app.py CHANGED
@@ -15,7 +15,18 @@ import time
15
  dotenv.load_dotenv()
16
 
17
  seamless_client = Client("facebook/seamless_m4t")
 
18
 
 
 
 
 
 
 
 
 
 
 
19
 
20
 
21
 
@@ -425,9 +436,16 @@ with gr.Blocks(theme='ParityError/Anime') as iface :
425
  audio_input = gr.Audio(label="speak",type="filepath",sources="microphone")
426
  audio_output = gr.Markdown(label="output text")
427
  audio_button = gr.Button("process audio")
 
 
 
 
 
428
  text_button.click(process_and_query, inputs=text_input, outputs=text_output)
429
  image_button.click(process_image, inputs=image_input, outputs=image_output)
430
  audio_button.click(process_speech, inputs=[audio_input,input_language], outputs=audio_output)
 
 
431
 
432
 
433
  iface.queue().launch(show_error=True,debug=True)
 
15
  dotenv.load_dotenv()
16
 
17
  seamless_client = Client("facebook/seamless_m4t")
18
+ HuggingFace_Token = os.getenv("HuggingFace_Token")
19
 
20
+ def check_hallucination(assertion,citation):
21
+ API_URL = "https://api-inference.huggingface.co/models/vectara/hallucination_evaluation_model"
22
+ headers = {"Authorization": f"Bearer {HuggingFace_Token}"}
23
+ payload = {"inputs" : f"{assertion} [SEP] {citation}"}
24
+
25
+ response = requests.post(API_URL, headers=headers, json=payload,timeout=120)
26
+ output = response.json()
27
+ output = output[0][0]["score"]
28
+
29
+ return f"**hullicination score:** {output}"
30
 
31
 
32
 
 
436
  audio_input = gr.Audio(label="speak",type="filepath",sources="microphone")
437
  audio_output = gr.Markdown(label="output text")
438
  audio_button = gr.Button("process audio")
439
+ with gr.Tab("hallucination check"):
440
+ assertion = gr.Textbox(label="assertion")
441
+ citation = gr.Textbox(label="citation text")
442
+ hullucination_output = gr.Markdown(label="output text")
443
+ audio_button = gr.Button("check hallucination")
444
  text_button.click(process_and_query, inputs=text_input, outputs=text_output)
445
  image_button.click(process_image, inputs=image_input, outputs=image_output)
446
  audio_button.click(process_speech, inputs=[audio_input,input_language], outputs=audio_output)
447
+ audio_button.click(check_hallucination,inputs=[assertion,citation],outputs=hullucination_output)
448
+
449
 
450
 
451
  iface.queue().launch(show_error=True,debug=True)