File size: 2,546 Bytes
5b45d10
297437a
e760939
5b45d10
297437a
e760939
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88f7b26
 
dc99d7c
235cd2f
46cd776
dc99d7c
e760939
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48

import gradio as gr
import requests
import os  

# Define the API parameters
API_URL = "https://api-inference.huggingface.co/models/vectara/hallucination_evaluation_model"
API_TOKEN = os.getenv("HF_AUTH_TOKEN")
if not API_TOKEN:
    raise ValueError("Please set the HF_AUTH_TOKEN environment variable.")

headers = {"Authorization": f"Bearer {API_TOKEN}"}

# Function to query the API
def query(payload):
    response = requests.post(API_URL, headers=headers, json=payload)
    return response.json()

# Function to be called by the Gradio interface
def evaluate_hallucination(input1, input2):
    # Combine the inputs
    combined_input = f"{input1}. {input2}"
    
    # Make the API call
    output = query({"inputs": combined_input})
    
    # Extract the score from the output
    score = output[0][0]['score']
    
    # Return a red or green circle based on the score
    if score < 0.5:
        return "🔴", "The score is less than 0.5"
    else:
        return "🟢", "The score is greater than 0.5"

# Create the Gradio interface
iface = gr.Interface(
    fn=evaluate_hallucination,
    inputs=[gr.Textbox(label="Assertion"), gr.Textbox(label="Citation")],
    outputs=[gr.Label(), gr.Textbox(label="Explanation")],
    live=False,
    title="👋🏻Welcome to 🌟Tonic's 🧠🌈Hallucination Tester 🔴🟢",
    description="How To Use 🌈Hallucination tester: 🗣️📝add any assertion from an LLM or a human 🗣️😷 add any citation from a RAG retriever or a source 👇🏻📩 Press send 🔴red means a 🌈hallucination, 🟢 green means a 🧠credible assertion. Check out the model [vectara/hallucination_evaluation_model](https://huggingface.co/vectara/hallucination_evaluation_model) You can also use 🥒🍆🫑Vectara - Hallucination Tester 🗣️😷 via API below or way by cloning this space. 🧬🔬🔍 Simply click here: Join us : 🌟TeamTonic🌟 is always making cool demos! Join our active builder's🛠️community 👻  [![Join us on Discord](https://img.shields.io/discord/1109943800132010065?label=Discord&logo=discord&style=flat-square)](https://discord.gg/GWpVpekp) On 🤗Huggingface: [TeamTonic](https://huggingface.co/TeamTonic) & [MultiTransformer](https://huggingface.co/MultiTransformer) On 🌐Github: [Tonic-AI](https://github.com/tonic-ai) & contribute to 🌟 [DataTonic](https://github.com/Tonic-AI/DataTonic) 🤗Big thanks to Yuvi Sharma and all the folks at huggingface for the community grant 🤗",
    theme='ParityError/Anime',
)

# Launch the interface
iface.launch()