Spaces:
abidlabs
/
Runtime error

ofermend commited on
Commit
aeadde1
1 Parent(s): fbddb3d

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -0
app.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+ import numpy as np
4
+
5
+ hhem = pipeline("text-classification", model="vectara/hallucination_evaluation_model")
6
+
7
+ def get_hhem_score(sentence1, sentence2):
8
+ output = hhem(f'{sentence1} [SEP] {sentence2}')
9
+ score = np.round(output[0]['score'], 4)
10
+
11
+ return score
12
+
13
+ demo = gr.Interface(
14
+ fn=get_hhem_score,
15
+ inputs=[
16
+ gr.components.Textbox(label="Sentence 1"),
17
+ gr.components.Textbox(label="Sentence 2"),
18
+ ],
19
+ outputs=gr.components.Label(num_top_classes=1, label='HHEM Score'),
20
+ examples=[
21
+ ["Vectara provides RAG-as-a-service", "RAG-as-a-service is provided by Vectara"],
22
+ ["The cat sat on the mat.", "A feline was resting on a small rug."],
23
+ ["The quick brown fox jumps over the lazy dog.", "A fast red fox leaps across a sleepy canine."],
24
+ ],
25
+ cache_examples=False,
26
+ allow_flagging="never",
27
+ flagging_options=None,
28
+ title="HHEM Demo",
29
+ description="This demo uses Vectara's Hallucination Evaluation model (HHEM) to calculate factual consistency between two input sentences.",
30
+ )
31
+
32
+ # Launch the demo
33
+ demo.launch()