|
|
|
import gradio as gr |
|
import requests |
|
import os |
|
|
|
|
|
API_URL = "/static-proxy?url=https%3A%2F%2Fapi-inference.huggingface.co%2Fmodels%2Fvectara%2Fhallucination_evaluation_model%26quot%3B%3C%2Fspan%3E%3C!-- HTML_TAG_END --> |
|
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}"} |
|
|
|
|
|
def query(payload): |
|
response = requests.post(API_URL, headers=headers, json=payload) |
|
return response.json() |
|
|
|
|
|
def evaluate_hallucination(input1, input2): |
|
|
|
combined_input = f"{input1}. {input2}" |
|
|
|
|
|
output = query({"inputs": combined_input}) |
|
|
|
|
|
score = output[0][0]['score'] |
|
|
|
|
|
if score < 0.5: |
|
return "🔴", "The score is less than 0.5" |
|
else: |
|
return "🟢", "The score is greater than 0.5" |
|
|
|
|
|
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', |
|
) |
|
|
|
|
|
iface.launch() |