forrestbao commited on
Commit
4e7ea3a
·
1 Parent(s): 580eabb
Files changed (5) hide show
  1. Dockerfile +20 -0
  2. README.md +3 -1
  3. app.py +46 -0
  4. requirements.txt +32 -0
  5. vectara_theme.py +29 -0
Dockerfile ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.10
2
+
3
+ WORKDIR /app
4
+
5
+ COPY ./vectara_theme.py /app/vectara_theme.py
6
+ COPY ./requirements.txt /app/requirements.txt
7
+ COPY ./app.py /app/app.py
8
+
9
+ # RUN apt-get update && apt-get install -y git-lfs
10
+
11
+ RUN pip install --no-cache-dir --upgrade -r /app/requirements.txt
12
+
13
+ # RUN useradd -m -u 1000 user
14
+ # ENV HOME=/home/user \
15
+ # PATH=/home/user/.local/bin:$PATH
16
+
17
+ # RUN mkdir -p /app/results
18
+ # RUN chown -R user /app
19
+
20
+ CMD ["funix", "app.py", "--host", "0.0.0.0", "--port", "7860", "--no-browser"]
README.md CHANGED
@@ -8,4 +8,6 @@ pinned: false
8
  short_description: The GUI demo for HHEM-2.1-Open
9
  ---
10
 
11
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
8
  short_description: The GUI demo for HHEM-2.1-Open
9
  ---
10
 
11
+ Vectara's HHEM 2.1 Open demo
12
+
13
+ Powered by [Funix.io](http://funix.io)
app.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # %%
2
+ from typing import List, Literal
3
+ from pydantic import BaseModel
4
+ from IPython.display import display, Markdown
5
+
6
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
7
+ from transformers import pipeline
8
+
9
+ # %%
10
+ class HHEMOutput(BaseModel):
11
+ score: float # we need score for ROC curve
12
+ label: Literal[0,1]
13
+
14
+ # %%
15
+ PROMPT_TEMPLATE = "<pad> Determine if the hypothesis is true given the premise?\n\nPremise: {text1}\n\nHypothesis: {text2}"
16
+
17
+ CHECKPOINT = "vectara/hallucination_evaluation_model"
18
+ FOUNDATION = "google/flan-t5-small"
19
+
20
+ tokenizer = AutoTokenizer.from_pretrained(FOUNDATION)
21
+ classifier = pipeline("text-classification", model=CHECKPOINT, tokenizer=tokenizer, trust_remote_code=True)
22
+
23
+ def predict(premise: str, hypothesis: str) -> Markdown:
24
+
25
+ texts_prompted: List[str] = [PROMPT_TEMPLATE.format(text1=premise, text2=hypothesis)]
26
+
27
+ full_scores = classifier(texts_prompted, top_k=None) # List[List[Dict[str, float]]]
28
+
29
+ # Optional: Extract the scores for the 'consistent' label
30
+ simple_scores = [score_dict['score'] for score_for_both_labels in full_scores for score_dict in score_for_both_labels if score_dict['label'] == 'consistent']
31
+
32
+ threshold = 0.5
33
+ preds = [0 if s < threshold else 1 for s in simple_scores]
34
+
35
+ output = HHEMOutput(score=simple_scores[0], label=preds[0])
36
+ verdict = "consistent" if output.label == 1 else "hallucinated"
37
+
38
+ output_string = f"""
39
+ **Premise**: {premise}
40
+
41
+ **Hypothesis**: {hypothesis}
42
+
43
+ **HHEM's judgement is**: {verdict} **with the score**: {output.score}
44
+ """
45
+
46
+ return Markdown(output_string)
requirements.txt ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ APScheduler==3.10.1
2
+ black==23.11.0
3
+ click==8.1.7
4
+ datasets==2.14.5
5
+ gradio==4.44.0
6
+ gradio_client==1.3.0
7
+ huggingface-hub>=0.18.0
8
+ litellm==1.15.1
9
+ matplotlib==3.7.1
10
+ numpy==1.26.4
11
+ pandas==2.0.0
12
+ python-dateutil==2.8.2
13
+ requests==2.31.0
14
+ tqdm==4.66.5
15
+ tokenizers>=0.15.0
16
+ sentence-transformers==2.2.2
17
+ google-generativeai
18
+ replicate
19
+ anthropic
20
+ openai
21
+ cohere
22
+ mistralai
23
+ peft
24
+ markdown-it-py
25
+ mdit_plain
26
+ google-cloud-aiplatform>=1.38
27
+ qwen-vl-utils
28
+ vertexai
29
+ # git+https://github.com/huggingface/transformers
30
+ transformers==4.45.2
31
+ together==1.3.0
32
+ spacy
vectara_theme.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ vectara_theme = {
2
+ "name": "vectara",
3
+ "funix": {
4
+ "run_button": "Refresh",
5
+ "grid_height": 960,
6
+ "grid_checkbox": False
7
+ },
8
+ "overrides": {
9
+ "MuiAppBar": {
10
+ "styleOverrides": {
11
+ "root": {
12
+ "backgroundColor": "#ffffff",
13
+ "color": "rgba(0, 0, 0, 0.87)",
14
+ "& .MuiToolbar-root:before": {
15
+ "content": '""',
16
+ "background": "url('https://huggingface.co/spaces/vectara/README/resolve/main/Vectara-logo.png')",
17
+ "display": "block",
18
+ "background-size": "contain",
19
+ "background-repeat": "no-repeat",
20
+ "background-position": "left",
21
+ "width": "125px",
22
+ "height": "40px",
23
+ "margin-right": "10px",
24
+ },
25
+ },
26
+ }
27
+ },
28
+ },
29
+ }