willsh1997 commited on
Commit
af7c8a8
·
1 Parent(s): 8731fa9

:sparkles: initial commit

Browse files
.github/workflows/push_to_hub.yml ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Sync to Hugging Face hub
2
+ on:
3
+ push:
4
+ branches: [main]
5
+
6
+ # to run this workflow manually from the Actions tab
7
+ workflow_dispatch:
8
+
9
+ jobs:
10
+ sync-to-hub:
11
+ runs-on: ubuntu-latest
12
+ steps:
13
+ - uses: actions/checkout@v3
14
+ with:
15
+ fetch-depth: 0
16
+ lfs: true
17
+ - name: Push to hub
18
+ env:
19
+ HF_TOKEN: ${{ secrets.HF_TOKEN }}
20
+ run: git push https://willsh1997:$HF_TOKEN@huggingface.co/spaces/willsh1997/widget-RAG main
.github/workflows/push_to_hub.yml.backup ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Sync to Hugging Face hub
2
+ on:
3
+ push:
4
+ branches: [main]
5
+
6
+ # to run this workflow manually from the Actions tab
7
+ workflow_dispatch:
8
+
9
+ jobs:
10
+ sync-to-hub:
11
+ runs-on: ubuntu-latest
12
+ steps:
13
+ - uses: actions/checkout@v3
14
+ with:
15
+ fetch-depth: 0
16
+ lfs: true
17
+ - name: Push to hub
18
+ env:
19
+ HF_TOKEN: ${{ secrets.HF_TOKEN }}
20
+ run: git push https://willsh1997:$HF_TOKEN@huggingface.co/spaces/willsh1997/moral-compass main
.gitignore CHANGED
@@ -1,6 +1,6 @@
1
  # Byte-compiled / optimized / DLL files
2
  __pycache__/
3
- *.py[codz]
4
  *$py.class
5
 
6
  # C extensions
@@ -46,7 +46,7 @@ htmlcov/
46
  nosetests.xml
47
  coverage.xml
48
  *.cover
49
- *.py.cover
50
  .hypothesis/
51
  .pytest_cache/
52
  cover/
@@ -106,24 +106,17 @@ ipython_config.py
106
  # commonly ignored for libraries.
107
  # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
108
  #poetry.lock
109
- #poetry.toml
110
 
111
  # pdm
112
  # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
113
- # pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
114
- # https://pdm-project.org/en/latest/usage/project/#working-with-version-control
115
  #pdm.lock
116
- #pdm.toml
 
 
 
117
  .pdm-python
118
  .pdm-build/
119
 
120
- # pixi
121
- # Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
122
- #pixi.lock
123
- # Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
124
- # in the .venv directory. It is recommended not to include this directory in version control.
125
- .pixi
126
-
127
  # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
128
  __pypackages__/
129
 
@@ -136,7 +129,6 @@ celerybeat.pid
136
 
137
  # Environments
138
  .env
139
- .envrc
140
  .venv
141
  env/
142
  venv/
@@ -185,7 +177,7 @@ cython_debug/
185
  # Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
186
  # that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
187
  # and can be added to the global gitignore or merged into this file. However, if you prefer,
188
- # you could uncomment the following to ignore the entire vscode folder
189
  # .vscode/
190
 
191
  # Ruff stuff:
@@ -199,9 +191,4 @@ cython_debug/
199
  # exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
200
  # refer to https://docs.cursor.com/context/ignore-files
201
  .cursorignore
202
- .cursorindexingignore
203
-
204
- # Marimo
205
- marimo/_static/
206
- marimo/_lsp/
207
- __marimo__/
 
1
  # Byte-compiled / optimized / DLL files
2
  __pycache__/
3
+ *.py[cod]
4
  *$py.class
5
 
6
  # C extensions
 
46
  nosetests.xml
47
  coverage.xml
48
  *.cover
49
+ *.py,cover
50
  .hypothesis/
51
  .pytest_cache/
52
  cover/
 
106
  # commonly ignored for libraries.
107
  # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
108
  #poetry.lock
 
109
 
110
  # pdm
111
  # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
 
 
112
  #pdm.lock
113
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
114
+ # in version control.
115
+ # https://pdm.fming.dev/latest/usage/project/#working-with-version-control
116
+ .pdm.toml
117
  .pdm-python
118
  .pdm-build/
119
 
 
 
 
 
 
 
 
120
  # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
121
  __pypackages__/
122
 
 
129
 
130
  # Environments
131
  .env
 
132
  .venv
133
  env/
134
  venv/
 
177
  # Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
178
  # that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
179
  # and can be added to the global gitignore or merged into this file. However, if you prefer,
180
+ # you could uncomment the following to ignore the enitre vscode folder
181
  # .vscode/
182
 
183
  # Ruff stuff:
 
191
  # exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
192
  # refer to https://docs.cursor.com/context/ignore-files
193
  .cursorignore
194
+ .cursorindexingignore
 
 
 
 
 
RAG-demo.py ADDED
@@ -0,0 +1,102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import spaces
2
+ from transformers import AutoModelForSeq2SeqLM, AutoTokenizer, BitsAndBytesConfig, AutoModelForCausalLM, GenerationConfig
3
+ import torch
4
+ from transformers import pipeline
5
+ import pandas as pd
6
+ import gradio as gr
7
+ from googlesearch import search
8
+
9
+ quantization_config = BitsAndBytesConfig(load_in_4bit=True)
10
+
11
+
12
+ #Llama 3.2 3b setup
13
+ llama3_model_id = "meta-llama/Llama-3.2-3B-Instruct"
14
+ llama3_pipe = pipeline(
15
+ "text-generation",
16
+ model=llama3_model_id,
17
+ torch_dtype=torch.bfloat16,
18
+ device_map="auto",
19
+ model_kwargs={"quantization_config": quantization_config},
20
+ )
21
+
22
+ #google search setup
23
+ def google_search_results(input_question: str):
24
+ outputGenerator = search(input_question, num_results=3, advanced=True)
25
+ outputs = []
26
+ for result in outputGenerator:
27
+ outputs.append(result.description)
28
+ return outputs
29
+
30
+ # adding RAG
31
+ def RAG_enrichment(input_question: str):
32
+ enrichment = google_search_results(input_question)
33
+ new_output = input_question + "\n\n Use the following information to help you respond: \n\n"
34
+ for info in enrichment:
35
+ new_output = new_output + info + "\n\n"
36
+ return new_output
37
+
38
+ @spaces.GPU
39
+ def llama_QA(input_question, pipe):
40
+ """
41
+ stupid func for asking llama a question and then getting an answer
42
+ inputs:
43
+ - input_question [str]: question for llama to answer
44
+ outputs:
45
+ - response [str]: llama's response
46
+ """
47
+ messages = [
48
+ {"role": "system", "content": "You are a helpful chatbot assistant. Answer all questions in the language they are asked in. Exclude any answer that you do not have real time information, just provide the information you have to answer this question."},
49
+ {"role": "user", "content": input_question},
50
+ ]
51
+
52
+ outputs = pipe(
53
+ messages,
54
+ max_new_tokens=512
55
+ )
56
+ response = outputs[0]["generated_text"][-1]['content']
57
+ return response
58
+
59
+
60
+ @spaces.GPU
61
+ def gradio_func(input_question, left_lang, right_lang):
62
+ """
63
+ silly wrapper function for gradio that turns all inputs into a single func. runs both the LHS and RHS of teh 'app' in order to let gradio work correctly.
64
+ """
65
+ input_1 = input_question
66
+ input_2 = RAG_enrichment(input_question)
67
+ output1 = llama_QA(input_question, llama3_pipe) #future2.result()
68
+ output2 = llama_QA(input_2, llama3_pipe) #future3.result()
69
+
70
+ return input_1, input_2, output1, output2
71
+
72
+ # Create the Gradio interface
73
+ def create_interface():
74
+
75
+ with gr.Blocks() as demo:
76
+ with gr.Row():
77
+ question_input = gr.Textbox(label="Enter your question", interactive=True, value = """Who is the current president of the United States?""")
78
+ with gr.Row():
79
+ submit_btn = gr.Button("Ask")
80
+ with gr.Row():
81
+ input1 = gr.Textbox(label="Qwen 3 output", interactive=False)
82
+ input2 = gr.Textbox(label="Gemma 3 output", interactive=False)
83
+ with gr.Row():
84
+ output1 = gr.Textbox(label="Qwen 3 output", interactive=False)
85
+ output2 = gr.Textbox(label="Gemma 3 output", interactive=False)
86
+
87
+ submit_btn.click(
88
+ fn=gradio_func,
89
+ inputs=[question_input],
90
+ outputs=[
91
+ input1,
92
+ input2,
93
+ output1,
94
+ output2,
95
+ ]
96
+ )
97
+
98
+ return demo
99
+
100
+ # Launch the app
101
+ demo = create_interface()
102
+ demo.launch()
README.md CHANGED
@@ -1,2 +1,14 @@
1
- # widget-RAG
2
- demo RAG widget for genai arcade
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: RAG demo
3
+ emoji: 🏆
4
+ colorFrom: pink
5
+ colorTo: yellow
6
+ sdk: gradio
7
+ sdk_version: 5.23.3
8
+ app_file: RAG-demo.py
9
+ pinned: false
10
+ license: apache-2.0
11
+ short_description: compare responses between non-RAG and RAG model
12
+ ---
13
+
14
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
requirements.txt ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ accelerate==1.4.0
2
+ aiofiles==23.2.1
3
+ annotated-types==0.7.0
4
+ anyio==4.8.0
5
+ asttokens==3.0.0
6
+ bitsandbytes==0.45.4
7
+ certifi==2025.1.31
8
+ charset-normalizer==3.4.1
9
+ click==8.1.8
10
+ comm==0.2.2
11
+ debugpy==1.8.12
12
+ decorator==5.1.1
13
+ exceptiongroup==1.2.2
14
+ executing==2.2.0
15
+ fastapi==0.115.8
16
+ ffmpy==0.5.0
17
+ filelock==3.17.0
18
+ fsspec==2025.2.0
19
+ gradio==5.16.1
20
+ gradio_client==1.7.0
21
+ h11==0.14.0
22
+ httpcore==1.0.7
23
+ httpx==0.28.1
24
+ huggingface-hub
25
+ idna==3.10
26
+ ipykernel==6.29.5
27
+ ipython==8.32.0
28
+ jedi==0.19.2
29
+ Jinja2==3.1.5
30
+ jupyter_client==8.6.3
31
+ jupyter_core==5.7.2
32
+ markdown-it-py==3.0.0
33
+ MarkupSafe==2.1.5
34
+ matplotlib-inline==0.1.7
35
+ mdurl==0.1.2
36
+ mpmath==1.3.0
37
+ nest-asyncio==1.6.0
38
+ networkx==3.4.2
39
+ numpy==2.2.3
40
+ orjson==3.10.15
41
+ packaging==24.2
42
+ pandas==2.2.3
43
+ parso==0.8.4
44
+ pexpect==4.9.0
45
+ pillow==11.1.0
46
+ platformdirs==4.3.6
47
+ prompt_toolkit==3.0.50
48
+ psutil==7.0.0
49
+ ptyprocess==0.7.0
50
+ pure_eval==0.2.3
51
+ pydantic==2.10.6
52
+ pydantic_core==2.27.2
53
+ pydub==0.25.1
54
+ Pygments==2.19.1
55
+ python-dateutil==2.9.0.post0
56
+ python-multipart==0.0.20
57
+ pytz==2025.1
58
+ PyYAML==6.0.2
59
+ pyzmq==26.2.1
60
+ regex==2024.11.6
61
+ requests==2.32.3
62
+ rich==13.9.4
63
+ ruff==0.9.6
64
+ safehttpx==0.1.6
65
+ safetensors==0.5.2
66
+ semantic-version==2.10.0
67
+ shellingham==1.5.4
68
+ six==1.17.0
69
+ sniffio==1.3.1
70
+ stack-data==0.6.3
71
+ starlette==0.45.3
72
+ sympy==1.13.1
73
+ tokenizers==0.21.0
74
+ tomlkit==0.13.2
75
+ torch==2.4.0
76
+ tornado==6.4.2
77
+ tqdm==4.67.1
78
+ traitlets==5.14.3
79
+ transformers==4.51.0
80
+ typer==0.15.1
81
+ typing_extensions==4.12.2
82
+ tzdata==2025.1
83
+ urllib3==2.3.0
84
+ uvicorn==0.34.0
85
+ wcwidth==0.2.13
86
+ websockets==14.2
87
+