Spaces:
Running
Running
add new interface
Browse files
app.py
CHANGED
@@ -2,6 +2,32 @@ import gradio as gr
|
|
2 |
from lettucedetect.models.inference import HallucinationDetector
|
3 |
import os
|
4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
# Initialize the LettuceDetect model
|
6 |
detector = HallucinationDetector(
|
7 |
method="transformer",
|
@@ -68,26 +94,14 @@ def evaluate_hallucination(context, question, answer):
|
|
68 |
|
69 |
# Gradio Blocks interface
|
70 |
with gr.Blocks(
|
71 |
-
title="🥬 LettuceDetect Hallucination Tester 🟢🔴"
|
72 |
-
theme="ParityError/Anime"
|
73 |
) as demo:
|
74 |
-
gr.Markdown(
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
1. Enter a **Context** (source document or info).
|
81 |
-
2. Enter a **Question** related to the context.
|
82 |
-
3. Enter an **Answer** to evaluate.
|
83 |
-
4. Press **Submit** to see if the answer hallucinates!
|
84 |
-
|
85 |
-
- 🟢 = No hallucinations
|
86 |
-
- 🔴 = Hallucinations detected
|
87 |
-
- Highlighted text shows hallucinated spans in **red** with confidence scores.
|
88 |
-
"""
|
89 |
-
)
|
90 |
-
|
91 |
with gr.Row():
|
92 |
with gr.Column(scale=2):
|
93 |
# Inputs
|
@@ -108,12 +122,15 @@ with gr.Blocks(
|
|
108 |
submit_btn = gr.Button("Submit")
|
109 |
|
110 |
with gr.Column(scale=3):
|
111 |
-
|
112 |
-
|
113 |
-
|
|
|
|
|
|
|
114 |
highlighted_answer_output = gr.HighlightedText(
|
115 |
label="Answer with Hallucinations Highlighted",
|
116 |
-
show_legend=
|
117 |
color_map={"hallucination": "red"}, # Note: Only "hallucination" is used as base category
|
118 |
combine_adjacent=True
|
119 |
)
|
|
|
2 |
from lettucedetect.models.inference import HallucinationDetector
|
3 |
import os
|
4 |
|
5 |
+
|
6 |
+
title = """# 🙋🏻♂️Welcome to 🌟Tonic's 🥬 LettuceDetect - 🤯🧠 Hallucination Tester 🟢🔴"""
|
7 |
+
description= """
|
8 |
+
Powered by `lettucedect-large-modernbert-en-v1` from KRLabsOrg. Detect hallucinations in answers based on context and questions using ModernBERT with 8192-token context support!
|
9 |
+
|
10 |
+
### How to Use:
|
11 |
+
1. Enter a **Context** (source document or info).
|
12 |
+
2. Enter a **Question** related to the context.
|
13 |
+
3. Enter an **Answer** to evaluate.
|
14 |
+
4. Press **Submit** to see if the answer hallucinates!
|
15 |
+
|
16 |
+
- 🟢 = No hallucinations
|
17 |
+
- 🔴 = Hallucinations detected
|
18 |
+
- Highlighted text shows hallucinated spans in **red** with confidence scores.
|
19 |
+
"""
|
20 |
+
join_us = """
|
21 |
+
## Join us:
|
22 |
+
🌟TeamTonic🌟 is always making cool demos! Join our active builder's 🛠️community 👻
|
23 |
+
[](https://discord.gg/n8ytYeh25n)
|
24 |
+
On 🤗Huggingface: [MultiTransformer](https://huggingface.co/MultiTransformer)
|
25 |
+
On 🌐Github: [Tonic-AI](https://github.com/tonic-ai) & contribute to🌟 [Data Tonic](https://github.com/multiTonic/thinking-dataset/)
|
26 |
+
🤗Big thanks to Yuvi Sharma and all the folks at huggingface for the community grant 🤗
|
27 |
+
"""
|
28 |
+
|
29 |
+
|
30 |
+
|
31 |
# Initialize the LettuceDetect model
|
32 |
detector = HallucinationDetector(
|
33 |
method="transformer",
|
|
|
94 |
|
95 |
# Gradio Blocks interface
|
96 |
with gr.Blocks(
|
97 |
+
title="🥬 LettuceDetect Hallucination Tester 🟢🔴"
|
|
|
98 |
) as demo:
|
99 |
+
gr.Markdown(title)
|
100 |
+
with gr.Row():
|
101 |
+
with gr.Group():
|
102 |
+
gr.Markdown(description)
|
103 |
+
with gr.Group():
|
104 |
+
gr.Markdown(join_us)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
with gr.Row():
|
106 |
with gr.Column(scale=2):
|
107 |
# Inputs
|
|
|
122 |
submit_btn = gr.Button("Submit")
|
123 |
|
124 |
with gr.Column(scale=3):
|
125 |
+
with gr.Row():
|
126 |
+
with gr.Column():
|
127 |
+
status_output = gr.Label(label="Status")
|
128 |
+
with gr.Column():
|
129 |
+
explanation_output = gr.Textbox(label="Explanation", interactive=False)
|
130 |
+
|
131 |
highlighted_answer_output = gr.HighlightedText(
|
132 |
label="Answer with Hallucinations Highlighted",
|
133 |
+
show_legend=False,
|
134 |
color_map={"hallucination": "red"}, # Note: Only "hallucination" is used as base category
|
135 |
combine_adjacent=True
|
136 |
)
|