tonic
commited on
Commit
•
e21a9f1
1
Parent(s):
e93a46f
Update app.py
Browse files
app.py
CHANGED
@@ -2,12 +2,24 @@
|
|
2 |
import gradio as gr
|
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)
|
@@ -121,11 +133,18 @@ def query_vectara(text):
|
|
121 |
else:
|
122 |
return f"Error: {response.status_code}"
|
123 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
124 |
# Create the Gradio interface
|
125 |
iface = gr.Interface(
|
126 |
-
fn=
|
127 |
-
inputs=[gr.Textbox(label="
|
128 |
-
outputs=[gr.
|
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)",
|
|
|
2 |
import gradio as gr
|
3 |
import requests
|
4 |
import os
|
5 |
+
import json
|
6 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
7 |
|
8 |
hf_token = os.getenv("HuggingFace_Token")
|
9 |
vapi_url = "https://api-inference.huggingface.co/models/vectara/hallucination_evaluation_model"
|
10 |
headers = {"Authorization": f"Bearer {hf_token}"}
|
11 |
|
12 |
|
13 |
+
model_name = "allenai/OLMo-1B"
|
14 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
15 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
16 |
+
|
17 |
+
def generate_text(prompt, max_new_tokens, top_k, top_p, do_sample):
|
18 |
+
inputs = tokenizer(prompt, return_tensors='pt', return_token_type_ids=False)
|
19 |
+
response = model.generate(**inputs, max_new_tokens=400, do_sample=Truee, top_k=50, top_p=0.95)
|
20 |
+
return tokenizer.batch_decode(response, skip_special_tokens=True)[0]
|
21 |
+
|
22 |
+
|
23 |
# Function to query the API
|
24 |
def query(payload):
|
25 |
response = requests.post(vapi_url, headers=headers, json=payload)
|
|
|
133 |
else:
|
134 |
return f"Error: {response.status_code}"
|
135 |
|
136 |
+
# Main function to integrate Vectara, OLMo, and hallucination check
|
137 |
+
def evaluate_content(user_input):
|
138 |
+
vectara_summary = query_vectara(user_input)
|
139 |
+
olmo_output = generate_text(vectara_summary)
|
140 |
+
hallucination_score = check_hallucination(olmo_output, vectara_summary)
|
141 |
+
return olmo_output, hallucination_score
|
142 |
+
|
143 |
# Create the Gradio interface
|
144 |
iface = gr.Interface(
|
145 |
+
fn=evaluate_content,
|
146 |
+
inputs=[gr.Textbox(label="User Input")],
|
147 |
+
outputs=[gr.Textbox(label="Generated Text"), gr.Textbox(label="Hallucination Score")],
|
148 |
live=False,
|
149 |
title="👋🏻Welcome to 🌟Team Tonic's 🧠🌈SureRAG🔴🟢",
|
150 |
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)",
|