Spaces:
Sleeping
Sleeping
h3110Fr13nd
commited on
Commit
•
14a6ed5
1
Parent(s):
b246a95
log
Browse files- assets/images (1).jpeg +0 -0
- assets/lelouch-lamperouge-zero-lelouch-lamperouge-zero-15225480-1280-720.jpg +0 -0
- assets/pngegg.png +0 -0
- main.py +51 -6
- utils.py +33 -2
assets/images (1).jpeg
ADDED
assets/lelouch-lamperouge-zero-lelouch-lamperouge-zero-15225480-1280-720.jpg
ADDED
assets/pngegg.png
ADDED
main.py
CHANGED
@@ -26,7 +26,7 @@ langchain.debug = True
|
|
26 |
|
27 |
dotenv.load_dotenv(".env", override=True)
|
28 |
|
29 |
-
print(os.environ.get("HF_EMAIL", "jsfvnjsdfv")
|
30 |
print(os.environ.get("HF_PASS"), "passv slkvn")
|
31 |
print(os.getenv("HF_EMAIL"), "skfjvdn")
|
32 |
print(os.getenv("HF_PASS"), "sfjkljgvhn")
|
@@ -116,7 +116,46 @@ Answer:
|
|
116 |
|
117 |
|
118 |
|
119 |
-
with gr.Blocks()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
120 |
gradio_app = GradioApp()
|
121 |
# link_buttons = []
|
122 |
# files = gr.Files(label="Upload Documents and Medical Reports", type="filepath", file_types=["pdf", "docx", "jpg", "jpeg", "png"])
|
@@ -125,23 +164,29 @@ with gr.Blocks() as demo:
|
|
125 |
infer_status = gr.Label("Infer Status: ", visible=False)
|
126 |
|
127 |
# upload_button.upload(gradio_app.upload_files, upload_button, [files, output_text])
|
128 |
-
chatbot = gr.Chatbot()
|
129 |
# with gr.Row():
|
130 |
# for link in range(5):
|
131 |
# btn = gr.Button(visible=False)
|
132 |
# link_buttons.append(btn)
|
133 |
-
|
134 |
-
|
|
|
|
|
|
|
135 |
# for link in range(5):
|
136 |
# print(gradio_app.links)
|
137 |
# btn.click(lambda: None, None, None, js=f"window.location.assign('{gradio_app.links[link]}');" if link < len(gradio_app.links) else None)
|
138 |
msg.submit(gradio_app.user, [msg, chatbot], [msg, chatbot], queue=False).then(
|
139 |
gradio_app.bot, chatbot, chatbot
|
140 |
)
|
|
|
|
|
|
|
141 |
# .then(
|
142 |
# gradio_app.list_links, None, link_buttons
|
143 |
# )
|
144 |
clear.click(lambda: None, None, chatbot, queue=False)
|
145 |
demo.queue()
|
146 |
-
demo.launch(
|
147 |
|
|
|
26 |
|
27 |
dotenv.load_dotenv(".env", override=True)
|
28 |
|
29 |
+
print(os.environ.get("HF_EMAIL"), "jsfvnjsdfv")
|
30 |
print(os.environ.get("HF_PASS"), "passv slkvn")
|
31 |
print(os.getenv("HF_EMAIL"), "skfjvdn")
|
32 |
print(os.getenv("HF_PASS"), "sfjkljgvhn")
|
|
|
116 |
|
117 |
|
118 |
|
119 |
+
with gr.Blocks(theme=gr.themes.Default(spacing_size=gr.themes.sizes.spacing_sm, radius_size=gr.themes.sizes.radius_md, ), css="""
|
120 |
+
|
121 |
+
* {
|
122 |
+
padding: 0px;
|
123 |
+
margin: 0px;
|
124 |
+
}
|
125 |
+
textarea {
|
126 |
+
border-radius: 10px;
|
127 |
+
padding: 10px;
|
128 |
+
}
|
129 |
+
|
130 |
+
button {
|
131 |
+
min-width: 20px;
|
132 |
+
min-height: 20px;
|
133 |
+
}
|
134 |
+
p:not(:first-child) {
|
135 |
+
margin-top: 1px;
|
136 |
+
margin-bottom: 1px;
|
137 |
+
}
|
138 |
+
.message.user{
|
139 |
+
padding: 10px;
|
140 |
+
padding-top: 5px;
|
141 |
+
padding-bottom: 5px;
|
142 |
+
}
|
143 |
+
.message.bot{
|
144 |
+
padding: 10px;
|
145 |
+
padding-top: 5px;
|
146 |
+
padding-bottom: 5px;
|
147 |
+
}
|
148 |
+
|
149 |
+
#clear {
|
150 |
+
|
151 |
+
color: white;
|
152 |
+
border-radius: 10px;
|
153 |
+
padding: 10px;
|
154 |
+
margin: 10px;
|
155 |
+
}
|
156 |
+
|
157 |
+
|
158 |
+
""" ) as demo:
|
159 |
gradio_app = GradioApp()
|
160 |
# link_buttons = []
|
161 |
# files = gr.Files(label="Upload Documents and Medical Reports", type="filepath", file_types=["pdf", "docx", "jpg", "jpeg", "png"])
|
|
|
164 |
infer_status = gr.Label("Infer Status: ", visible=False)
|
165 |
|
166 |
# upload_button.upload(gradio_app.upload_files, upload_button, [files, output_text])
|
167 |
+
chatbot = gr.Chatbot(avatar_images=["assets/images (1).jpeg", "assets/lelouch-lamperouge-zero-lelouch-lamperouge-zero-15225480-1280-720.jpg"])
|
168 |
# with gr.Row():
|
169 |
# for link in range(5):
|
170 |
# btn = gr.Button(visible=False)
|
171 |
# link_buttons.append(btn)
|
172 |
+
|
173 |
+
with gr.Row() as row:
|
174 |
+
msg = gr.Textbox(show_label=False, placeholder="Type your message here", scale=20)
|
175 |
+
submit_btn = gr.Button("", icon="assets/pngegg.png",)
|
176 |
+
clear = gr.Button("Clear", elem_id="clear")
|
177 |
# for link in range(5):
|
178 |
# print(gradio_app.links)
|
179 |
# btn.click(lambda: None, None, None, js=f"window.location.assign('{gradio_app.links[link]}');" if link < len(gradio_app.links) else None)
|
180 |
msg.submit(gradio_app.user, [msg, chatbot], [msg, chatbot], queue=False).then(
|
181 |
gradio_app.bot, chatbot, chatbot
|
182 |
)
|
183 |
+
submit_btn.click(gradio_app.user, [msg, chatbot], [msg, chatbot], queue=False).then(
|
184 |
+
gradio_app.bot, chatbot, chatbot
|
185 |
+
)
|
186 |
# .then(
|
187 |
# gradio_app.list_links, None, link_buttons
|
188 |
# )
|
189 |
clear.click(lambda: None, None, chatbot, queue=False)
|
190 |
demo.queue()
|
191 |
+
demo.launch(server_name="0.0.0.0", root_path="/app")
|
192 |
|
utils.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
from hugchat import hugchat
|
2 |
-
|
3 |
import time
|
4 |
|
5 |
from typing import Any, List, Mapping, Optional
|
@@ -14,6 +14,35 @@ from langchain.llms.base import LLM
|
|
14 |
# - HugChat library : https://github.com/Soulter/hugging-chat-api
|
15 |
# - I am Alessandro Ciciarelli the owner of IntelligenzaArtificialeItalia.net , my dream is to democratize AI and make it accessible to everyone.
|
16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
class HuggingChat(LLM):
|
18 |
|
19 |
"""HuggingChat LLM wrapper."""
|
@@ -58,7 +87,7 @@ class HuggingChat(LLM):
|
|
58 |
try:
|
59 |
if self.email and self.psw:
|
60 |
# Create a ChatBot using email and psw
|
61 |
-
|
62 |
start_time = time.time()
|
63 |
sign = Login(self.email, self.psw)
|
64 |
cookies = sign.login()
|
@@ -156,3 +185,5 @@ class HuggingChat(LLM):
|
|
156 |
"""Get the average response time."""
|
157 |
return self.avg_response_time
|
158 |
|
|
|
|
|
|
1 |
from hugchat import hugchat
|
2 |
+
from hugchat.login import Login
|
3 |
import time
|
4 |
|
5 |
from typing import Any, List, Mapping, Optional
|
|
|
14 |
# - HugChat library : https://github.com/Soulter/hugging-chat-api
|
15 |
# - I am Alessandro Ciciarelli the owner of IntelligenzaArtificialeItalia.net , my dream is to democratize AI and make it accessible to everyone.
|
16 |
|
17 |
+
class Login(Login):
|
18 |
+
def _get_auth_url(self):
|
19 |
+
url = "https://huggingface.co/chat/login"
|
20 |
+
headers = {
|
21 |
+
"Referer": "https://huggingface.co/chat/login",
|
22 |
+
"User-Agent": self.headers["User-Agent"],
|
23 |
+
"Content-Type": "application/x-www-form-urlencoded",
|
24 |
+
"Origin": "https://huggingface.co/chat"
|
25 |
+
}
|
26 |
+
res = self._request_post(url, headers=headers, allow_redirects=False)
|
27 |
+
print(res.status_code, res.headers, res.text, "\n ----------------------------------------------------------------------")
|
28 |
+
if res.status_code == 200:
|
29 |
+
# location = res.headers.get("Location", None)
|
30 |
+
location = res.json()["location"]
|
31 |
+
if location:
|
32 |
+
return location
|
33 |
+
else:
|
34 |
+
raise Exception(
|
35 |
+
"No authorize url found, please check your email or password.")
|
36 |
+
elif res.status_code == 303:
|
37 |
+
location = res.headers.get("Location")
|
38 |
+
if location:
|
39 |
+
return location
|
40 |
+
else:
|
41 |
+
raise Exception(
|
42 |
+
"No authorize url found, please check your email or password.")
|
43 |
+
else:
|
44 |
+
raise Exception("Something went wrong!")
|
45 |
+
|
46 |
class HuggingChat(LLM):
|
47 |
|
48 |
"""HuggingChat LLM wrapper."""
|
|
|
87 |
try:
|
88 |
if self.email and self.psw:
|
89 |
# Create a ChatBot using email and psw
|
90 |
+
|
91 |
start_time = time.time()
|
92 |
sign = Login(self.email, self.psw)
|
93 |
cookies = sign.login()
|
|
|
185 |
"""Get the average response time."""
|
186 |
return self.avg_response_time
|
187 |
|
188 |
+
|
189 |
+
|