Spaces:
Runtime error
Runtime error
Base
Browse files- .gitignore +161 -0
- README.md +4 -4
- app.py +43 -0
- requirements.txt +3 -0
- src/brain.py +11 -0
- src/content.html +8 -0
- src/style.css +68 -0
.gitignore
ADDED
@@ -0,0 +1,161 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# user Defined
|
2 |
+
*.db
|
3 |
+
.env
|
4 |
+
*.pdf
|
5 |
+
*.json
|
6 |
+
temp/*
|
7 |
+
|
8 |
+
|
9 |
+
|
10 |
+
# Byte-compiled / optimized / DLL files
|
11 |
+
__pycache__/
|
12 |
+
*.py[cod]
|
13 |
+
*$py.class
|
14 |
+
|
15 |
+
# C extensions
|
16 |
+
*.so
|
17 |
+
|
18 |
+
# Distribution / packaging
|
19 |
+
.Python
|
20 |
+
build/
|
21 |
+
develop-eggs/
|
22 |
+
dist/
|
23 |
+
downloads/
|
24 |
+
eggs/
|
25 |
+
.eggs/
|
26 |
+
lib/
|
27 |
+
lib64/
|
28 |
+
parts/
|
29 |
+
sdist/
|
30 |
+
var/
|
31 |
+
wheels/
|
32 |
+
share/python-wheels/
|
33 |
+
*.egg-info/
|
34 |
+
.installed.cfg
|
35 |
+
*.egg
|
36 |
+
MANIFEST
|
37 |
+
|
38 |
+
# PyInstaller
|
39 |
+
# Usually these files are written by a python script from a template
|
40 |
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
41 |
+
*.manifest
|
42 |
+
*.spec
|
43 |
+
|
44 |
+
# Installer logs
|
45 |
+
pip-log.txt
|
46 |
+
pip-delete-this-directory.txt
|
47 |
+
|
48 |
+
# Unit test / coverage reports
|
49 |
+
htmlcov/
|
50 |
+
.tox/
|
51 |
+
.nox/
|
52 |
+
.coverage
|
53 |
+
.coverage.*
|
54 |
+
.cache
|
55 |
+
nosetests.xml
|
56 |
+
coverage.xml
|
57 |
+
*.cover
|
58 |
+
*.py,cover
|
59 |
+
.hypothesis/
|
60 |
+
.pytest_cache/
|
61 |
+
cover/
|
62 |
+
|
63 |
+
# Translations
|
64 |
+
*.mo
|
65 |
+
*.pot
|
66 |
+
|
67 |
+
# Django stuff:
|
68 |
+
*.log
|
69 |
+
local_settings.py
|
70 |
+
db.sqlite3
|
71 |
+
db.sqlite3-journal
|
72 |
+
|
73 |
+
# Flask stuff:
|
74 |
+
instance/
|
75 |
+
.webassets-cache
|
76 |
+
|
77 |
+
# Scrapy stuff:
|
78 |
+
.scrapy
|
79 |
+
|
80 |
+
# Sphinx documentation
|
81 |
+
docs/_build/
|
82 |
+
|
83 |
+
# PyBuilder
|
84 |
+
.pybuilder/
|
85 |
+
target/
|
86 |
+
|
87 |
+
# Jupyter Notebook
|
88 |
+
.ipynb_checkpoints
|
89 |
+
|
90 |
+
# IPython
|
91 |
+
profile_default/
|
92 |
+
ipython_config.py
|
93 |
+
|
94 |
+
# pyenv
|
95 |
+
# For a library or package, you might want to ignore these files since the code is
|
96 |
+
# intended to run in multiple environments; otherwise, check them in:
|
97 |
+
# .python-version
|
98 |
+
|
99 |
+
# pipenv
|
100 |
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
101 |
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
102 |
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
103 |
+
# install all needed dependencies.
|
104 |
+
#Pipfile.lock
|
105 |
+
|
106 |
+
# poetry
|
107 |
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
108 |
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
109 |
+
# commonly ignored for libraries.
|
110 |
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
111 |
+
#poetry.lock
|
112 |
+
|
113 |
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
|
114 |
+
__pypackages__/
|
115 |
+
|
116 |
+
# Celery stuff
|
117 |
+
celerybeat-schedule
|
118 |
+
celerybeat.pid
|
119 |
+
|
120 |
+
# SageMath parsed files
|
121 |
+
*.sage.py
|
122 |
+
|
123 |
+
# Environments
|
124 |
+
.env
|
125 |
+
.venv
|
126 |
+
env/
|
127 |
+
venv/
|
128 |
+
ENV/
|
129 |
+
env.bak/
|
130 |
+
venv.bak/
|
131 |
+
|
132 |
+
# Spyder project settings
|
133 |
+
.spyderproject
|
134 |
+
.spyproject
|
135 |
+
|
136 |
+
# Rope project settings
|
137 |
+
.ropeproject
|
138 |
+
|
139 |
+
# mkdocs documentation
|
140 |
+
/site
|
141 |
+
|
142 |
+
# mypy
|
143 |
+
.mypy_cache/
|
144 |
+
.dmypy.json
|
145 |
+
dmypy.json
|
146 |
+
|
147 |
+
# Pyre type checker
|
148 |
+
.pyre/
|
149 |
+
|
150 |
+
# pytype static type analyzer
|
151 |
+
.pytype/
|
152 |
+
|
153 |
+
# Cython debug symbols
|
154 |
+
cython_debug/
|
155 |
+
|
156 |
+
# PyCharm
|
157 |
+
# JetBrains specific template is maintainted in a separate JetBrains.gitignore that can
|
158 |
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
159 |
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
160 |
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
161 |
+
#.idea/
|
README.md
CHANGED
@@ -1,13 +1,13 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
colorTo: green
|
6 |
sdk: gradio
|
7 |
sdk_version: 4.19.1
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
-
license:
|
11 |
---
|
12 |
|
13 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
---
|
2 |
+
title: Talk To Doc-Advanced Reasoning And QA With Gemini Pro
|
3 |
+
emoji: 🦀
|
4 |
+
colorFrom: green
|
5 |
colorTo: green
|
6 |
sdk: gradio
|
7 |
sdk_version: 4.19.1
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
+
license: apache-2.0
|
11 |
---
|
12 |
|
13 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
pdf_loaded = False
|
3 |
+
processing = False
|
4 |
+
from src.brain import generate_answers
|
5 |
+
|
6 |
+
def response(query, history):
|
7 |
+
global processing
|
8 |
+
if not pdf_loaded or processing:
|
9 |
+
return "Please wait...", history
|
10 |
+
processing = True
|
11 |
+
output = generate_answers(query)
|
12 |
+
history.append((query, output))
|
13 |
+
processing = False
|
14 |
+
return "", history
|
15 |
+
|
16 |
+
|
17 |
+
with open("src/style.css", "r") as file:
|
18 |
+
css = file.read()
|
19 |
+
|
20 |
+
with open("src/content.html", "r") as file:
|
21 |
+
html_content = file.read()
|
22 |
+
parts = html_content.split("<!-- split here -->")
|
23 |
+
title_html = parts[0]
|
24 |
+
bts_html = parts[1] if len(parts) > 1 else ""
|
25 |
+
|
26 |
+
def loading():
|
27 |
+
return "Loading ..."
|
28 |
+
|
29 |
+
with gr.Blocks(css=css) as app:
|
30 |
+
with gr.Column(elem_id="column_container"):
|
31 |
+
gr.HTML(title_html)
|
32 |
+
chatbot = gr.Chatbot([], elem_id="chatbot")
|
33 |
+
with gr.Column():
|
34 |
+
send = gr.Label(value="Write your QUESTION bellow and hit ENTER")
|
35 |
+
query = gr.Textbox(
|
36 |
+
label="Type your questions here:",
|
37 |
+
placeholder="What do you want to know?",
|
38 |
+
)
|
39 |
+
clear = gr.ClearButton([query, chatbot])
|
40 |
+
gr.HTML(bts_html)
|
41 |
+
query.submit(response, [query, chatbot], [query, chatbot], queue=True)
|
42 |
+
|
43 |
+
app.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
bitsandbytes
|
2 |
+
accelerate
|
3 |
+
transformers
|
src/brain.py
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
2 |
+
|
3 |
+
model_name = "google/gemma-2b"
|
4 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
5 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
6 |
+
|
7 |
+
|
8 |
+
def generate_answers(query):
|
9 |
+
input_ids = tokenizer(**query, return_tensors="pt")
|
10 |
+
output = model.generate(input_ids)
|
11 |
+
return tokenizer.decode(output[0])
|
src/content.html
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<div id="column_container">
|
2 |
+
</div>
|
3 |
+
|
4 |
+
<!-- split here -->
|
5 |
+
|
6 |
+
<div id="column_container">
|
7 |
+
<h2>What's Happening Behind the Scenes?</h2>
|
8 |
+
</div>
|
src/style.css
ADDED
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
body {
|
2 |
+
background-color: #171717;
|
3 |
+
font-family: 'San Francisco', 'Helvetica Neue', sans-serif;
|
4 |
+
color: rgb(43, 51, 49)
|
5 |
+
}
|
6 |
+
|
7 |
+
#column_container {
|
8 |
+
max-width: 80%;
|
9 |
+
margin: auto;
|
10 |
+
background-color: #19273c80;
|
11 |
+
border-radius: 12px;
|
12 |
+
box-shadow: 0 4px 8px rgba(108, 247, 242, 0.372);
|
13 |
+
padding: 40px;
|
14 |
+
}
|
15 |
+
|
16 |
+
h1 {
|
17 |
+
color: #58ffb1;
|
18 |
+
text-align: center;
|
19 |
+
font-family: 'Avenir Next', 'Helvetica Neue', sans-serif;
|
20 |
+
font-size: 3em;
|
21 |
+
}
|
22 |
+
|
23 |
+
h2 {
|
24 |
+
color: #ffffff;
|
25 |
+
text-align: center;
|
26 |
+
font-family: 'Avenir Next', 'Helvetica Neue', sans-serif;
|
27 |
+
font-size: 2em;
|
28 |
+
}
|
29 |
+
|
30 |
+
p,
|
31 |
+
li {
|
32 |
+
color: #ffffff;
|
33 |
+
line-height: 1.6;
|
34 |
+
font-family: 'Georgia', serif;
|
35 |
+
|
36 |
+
}
|
37 |
+
|
38 |
+
strong {
|
39 |
+
color: #a3fdd3;
|
40 |
+
}
|
41 |
+
|
42 |
+
ul {
|
43 |
+
list-style: none;
|
44 |
+
padding: 0;
|
45 |
+
margin: 20px 0;
|
46 |
+
}
|
47 |
+
|
48 |
+
li {
|
49 |
+
padding-left: 20px;
|
50 |
+
position: relative;
|
51 |
+
}
|
52 |
+
|
53 |
+
button {
|
54 |
+
background-color: #2b0808;
|
55 |
+
color: #ff0000;
|
56 |
+
border: none;
|
57 |
+
border-radius: 8px;
|
58 |
+
padding: 14px 24px;
|
59 |
+
cursor: pointer;
|
60 |
+
font-family: inherit;
|
61 |
+
font-size: 1em;
|
62 |
+
transition: background-color 0.3s ease;
|
63 |
+
box-shadow: 0 1px 3px rgba(255, 94, 94, 0.753);
|
64 |
+
|
65 |
+
button:hover {
|
66 |
+
background-color: #55a369;
|
67 |
+
}
|
68 |
+
}
|