tonic commited on
Commit
e93a46f
1 Parent(s): fa0faa4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -43
app.py CHANGED
@@ -3,6 +3,16 @@ import gradio as gr
3
  import requests
4
  import os
5
 
 
 
 
 
 
 
 
 
 
 
6
  def check_hallucination(assertion, citation):
7
  api_url = "https://api-inference.huggingface.co/models/vectara/hallucination_evaluation_model"
8
  header = {"Authorization": f"Bearer {hf_token}"}
@@ -15,52 +25,15 @@ def check_hallucination(assertion, citation):
15
  return f"**hallucination score:** {output}"
16
 
17
 
18
- # Define the API parameters
19
- vapi_url = "https://api-inference.huggingface.co/models/vectara/hallucination_evaluation_model"
20
-
21
- headers = {"Authorization": f"Bearer {hf_token}"}
22
-
23
-
24
- # Function to query the API
25
- def query(payload):
26
- response = requests.post(vapi_url, headers=headers, json=payload)
27
- return response.json()
28
-
29
-
30
- # Function to evaluate hallucination
31
- def evaluate_hallucination(input1, input2):
32
- # Combine the inputs
33
- combined_input = f"{input1}. {input2}"
34
-
35
- # Make the API call
36
- output = query({"inputs": combined_input})
37
-
38
- # Extract the score from the output
39
- score = output[0][0]['score']
40
-
41
- # Generate a label based on the score
42
- if score < 0.5:
43
- label = f"🔴 High risk. Score: {score:.2f}"
44
- else:
45
- label = f"🟢 Low risk. Score: {score:.2f}"
46
-
47
- return label
48
-
49
  def query_vectara(text):
50
  user_message = text
51
-
52
- # Read authentication parameters from the .env file
53
  customer_id = os.getenv('CUSTOMER_ID')
54
  corpus_id = os.getenv('CORPUS_ID')
55
  api_key = os.getenv('API_KEY')
56
-
57
- # Define the headers
58
  api_key_header = {
59
  "customer-id": customer_id,
60
  "x-api-key": api_key
61
  }
62
-
63
- # Define the request body in the structure provided in the example
64
  request_body = {
65
  "query": [
66
  {
@@ -104,11 +77,9 @@ def query_vectara(text):
104
  }
105
  ]
106
  }
107
-
108
- # Make the API request using Gradio
109
  response = requests.post(
110
  "https://api.vectara.io/v1/query",
111
- json=request_body, # Use json to automatically serialize the request body
112
  verify=True,
113
  headers=api_key_header
114
  )
@@ -156,9 +127,8 @@ iface = gr.Interface(
156
  inputs=[gr.Textbox(label="Assertion"), gr.Textbox(label="Citation")],
157
  outputs=[gr.Label(), gr.Textbox(label="Explanation")],
158
  live=False,
159
- title="👋🏻Welcome to 🌟Tonic's 🧠🌈Hallucination Tester 🔴🟢",
160
- 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 🤗",
161
- theme='ParityError/Anime',
162
  )
163
 
164
  # Launch the interface
 
3
  import requests
4
  import os
5
 
6
+ hf_token = os.getenv("HuggingFace_Token")
7
+ vapi_url = "https://api-inference.huggingface.co/models/vectara/hallucination_evaluation_model"
8
+ headers = {"Authorization": f"Bearer {hf_token}"}
9
+
10
+
11
+ # Function to query the API
12
+ def query(payload):
13
+ response = requests.post(vapi_url, headers=headers, json=payload)
14
+ return response.json()
15
+
16
  def check_hallucination(assertion, citation):
17
  api_url = "https://api-inference.huggingface.co/models/vectara/hallucination_evaluation_model"
18
  header = {"Authorization": f"Bearer {hf_token}"}
 
25
  return f"**hallucination score:** {output}"
26
 
27
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  def query_vectara(text):
29
  user_message = text
 
 
30
  customer_id = os.getenv('CUSTOMER_ID')
31
  corpus_id = os.getenv('CORPUS_ID')
32
  api_key = os.getenv('API_KEY')
 
 
33
  api_key_header = {
34
  "customer-id": customer_id,
35
  "x-api-key": api_key
36
  }
 
 
37
  request_body = {
38
  "query": [
39
  {
 
77
  }
78
  ]
79
  }
 
 
80
  response = requests.post(
81
  "https://api.vectara.io/v1/query",
82
+ json=request_body,
83
  verify=True,
84
  headers=api_key_header
85
  )
 
127
  inputs=[gr.Textbox(label="Assertion"), gr.Textbox(label="Citation")],
128
  outputs=[gr.Label(), gr.Textbox(label="Explanation")],
129
  live=False,
130
+ title="👋🏻Welcome to 🌟Team Tonic's 🧠🌈SureRAG🔴🟢",
131
+ description="Nothing is more important than reputation. However you can create automated content pipelines for public facing content. How can businesses grow their reputation while mitigating risks due to AI? How it works : vectara rag retrieval reranking and summarization is used to return content. then an LLM generates content based on these returns. this content is checked for hallucination before being validated for publishing on twitter. SureRAG is fixed on Tonic-AI's README files as a Demo, provide input to generate a response. This response is checked by Vectara's HHME. Check out the model [vectara/hallucination_evaluation_model](https://huggingface.co/vectara/hallucination_evaluation_model) 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)",
 
132
  )
133
 
134
  # Launch the interface