Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,19 +1,46 @@
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import InferenceClient
|
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
"""
|
5 |
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
6 |
"""
|
7 |
client = InferenceClient("QuantFactory/Meta-Llama-3-8B-Instruct-GGUF")#("HuggingFaceH4/zephyr-7b-beta")
|
8 |
|
|
|
9 |
|
10 |
def respond(
|
11 |
-
message,
|
12 |
history: list[tuple[str, str]],
|
13 |
system_message,
|
14 |
-
max_tokens,
|
15 |
-
temperature,
|
16 |
-
top_p,
|
17 |
):
|
18 |
messages = [{"role": "system", "content": system_message}]
|
19 |
|
@@ -45,16 +72,16 @@ For information on how to customize the ChatInterface, peruse the gradio docs: h
|
|
45 |
demo = gr.ChatInterface(
|
46 |
respond,
|
47 |
additional_inputs=[
|
48 |
-
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
49 |
-
gr.Slider(minimum=1, maximum=
|
50 |
-
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
51 |
-
gr.Slider(
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
),
|
58 |
],
|
59 |
)
|
60 |
|
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import InferenceClient
|
3 |
|
4 |
+
import requests
|
5 |
+
from bs4 import BeautifulSoup
|
6 |
+
from bs4.element import Comment
|
7 |
+
|
8 |
+
def get_text_from_url(url):
|
9 |
+
response = requests.get(url)
|
10 |
+
soup = BeautifulSoup(response.text, 'html.parser')
|
11 |
+
texts = soup.find_all(text=True)
|
12 |
+
visible_texts = filter(tag_visible, texts)
|
13 |
+
return u"\n".join(t.strip() for t in visible_texts)
|
14 |
+
|
15 |
+
def tag_visible(element):
|
16 |
+
if element.parent.name in ['style', 'script', 'head', 'title', 'meta', '[document]']:
|
17 |
+
return False
|
18 |
+
if isinstance(element, Comment):
|
19 |
+
return False
|
20 |
+
return True
|
21 |
+
|
22 |
+
text_list = []
|
23 |
+
homepage_url = "https://sites.google.com/view/abhilashnandy/home/"
|
24 |
+
extensions = ["", "about", "curriculum-vitae", "pmrf-profile-page", "publications"]
|
25 |
+
for ext in extensions:
|
26 |
+
url_text = get_text_from_url(homepage_url+ext)
|
27 |
+
text_list.append(url_text)
|
28 |
+
# Repeat for sub-links if necessary
|
29 |
+
|
30 |
"""
|
31 |
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
32 |
"""
|
33 |
client = InferenceClient("QuantFactory/Meta-Llama-3-8B-Instruct-GGUF")#("HuggingFaceH4/zephyr-7b-beta")
|
34 |
|
35 |
+
SYSTEM_MESSAGE = "You are a QA chatbot to answer queries on my homepage that has the following information -\n\n" + "\n\n".join(text_list)
|
36 |
|
37 |
def respond(
|
38 |
+
message = SYSTEM_MESSAGE,
|
39 |
history: list[tuple[str, str]],
|
40 |
system_message,
|
41 |
+
max_tokens=200,
|
42 |
+
temperature=0.7,
|
43 |
+
top_p=0.95,
|
44 |
):
|
45 |
messages = [{"role": "system", "content": system_message}]
|
46 |
|
|
|
72 |
demo = gr.ChatInterface(
|
73 |
respond,
|
74 |
additional_inputs=[
|
75 |
+
# gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
76 |
+
# gr.Slider(minimum=1, maximum=8192, value=512, step=1, label="Max new tokens"),
|
77 |
+
# gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
78 |
+
# gr.Slider(
|
79 |
+
# minimum=0.1,
|
80 |
+
# maximum=1.0,
|
81 |
+
# value=0.95,
|
82 |
+
# step=0.05,
|
83 |
+
# label="Top-p (nucleus sampling)",
|
84 |
+
# ),
|
85 |
],
|
86 |
)
|
87 |
|