Update app.py
Browse files
app.py
CHANGED
|
@@ -6,15 +6,13 @@ from huggingface_hub import InferenceClient
|
|
| 6 |
import re
|
| 7 |
from datetime import datetime
|
| 8 |
import json
|
| 9 |
-
|
| 10 |
import arxiv
|
| 11 |
from utils import get_md_text_abstract, search_cleaner, get_arxiv_live_search
|
| 12 |
|
| 13 |
retrieve_results = 10
|
| 14 |
show_examples = False
|
| 15 |
-
llm_models_to_choose = ['mistralai/Mixtral-8x7B-Instruct-v0.1','mistralai/Mistral-7B-Instruct-v0.2', 'google/gemma-
|
| 16 |
-
|
| 17 |
-
token = os.getenv("HF_TOKEN")
|
| 18 |
|
| 19 |
generate_kwargs = dict(
|
| 20 |
temperature = None,
|
|
@@ -35,8 +33,8 @@ except:
|
|
| 35 |
gr.Warning("Retriever not working!")
|
| 36 |
|
| 37 |
## Header
|
| 38 |
-
mark_text = '#
|
| 39 |
-
header_text = "
|
| 40 |
|
| 41 |
try:
|
| 42 |
with open("README.md", "r") as f:
|
|
@@ -55,7 +53,7 @@ database_choices = [index_info,'Arxiv Search - Latest - (EXPERIMENTAL)']
|
|
| 55 |
## Arxiv API
|
| 56 |
arx_client = arxiv.Client()
|
| 57 |
is_arxiv_available = True
|
| 58 |
-
check_arxiv_result = get_arxiv_live_search("What is
|
| 59 |
if len(check_arxiv_result) == 0:
|
| 60 |
is_arxiv_available = False
|
| 61 |
print("Arxiv search not working, switching to default search ...")
|
|
@@ -102,6 +100,35 @@ def get_references(question, retriever, k = retrieve_results):
|
|
| 102 |
def get_rag(message):
|
| 103 |
return get_references(message, RAG)
|
| 104 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
with gr.Blocks(theme = gr.themes.Soft()) as demo:
|
| 106 |
header = gr.Markdown(header_text)
|
| 107 |
|
|
@@ -164,7 +191,7 @@ with gr.Blocks(theme = gr.themes.Soft()) as demo:
|
|
| 164 |
else:
|
| 165 |
return model_disabled_text
|
| 166 |
|
| 167 |
-
client = InferenceClient(llm_model_picked
|
| 168 |
try:
|
| 169 |
stream = client.text_generation(prompt, **generate_kwargs, stream=stream_outputs, details=False, return_full_text=False)
|
| 170 |
|
|
@@ -175,6 +202,7 @@ with gr.Blocks(theme = gr.themes.Soft()) as demo:
|
|
| 175 |
if stream_outputs:
|
| 176 |
for response in stream:
|
| 177 |
output += response
|
|
|
|
| 178 |
yield output
|
| 179 |
return output
|
| 180 |
else:
|
|
|
|
| 6 |
import re
|
| 7 |
from datetime import datetime
|
| 8 |
import json
|
| 9 |
+
|
| 10 |
import arxiv
|
| 11 |
from utils import get_md_text_abstract, search_cleaner, get_arxiv_live_search
|
| 12 |
|
| 13 |
retrieve_results = 10
|
| 14 |
show_examples = False
|
| 15 |
+
llm_models_to_choose = ['mistralai/Mixtral-8x7B-Instruct-v0.1','mistralai/Mistral-7B-Instruct-v0.2', 'google/gemma-7b-it', 'None']
|
|
|
|
|
|
|
| 16 |
|
| 17 |
generate_kwargs = dict(
|
| 18 |
temperature = None,
|
|
|
|
| 33 |
gr.Warning("Retriever not working!")
|
| 34 |
|
| 35 |
## Header
|
| 36 |
+
mark_text = '# 🩺🔍 Search Results\n'
|
| 37 |
+
header_text = "## Arxiv Paper Summary With QA Retrieval Augmented Generation \n"
|
| 38 |
|
| 39 |
try:
|
| 40 |
with open("README.md", "r") as f:
|
|
|
|
| 53 |
## Arxiv API
|
| 54 |
arx_client = arxiv.Client()
|
| 55 |
is_arxiv_available = True
|
| 56 |
+
check_arxiv_result = get_arxiv_live_search("What is Self Rewarding AI and how can it be used in Multi-Agent Systems?", arx_client, retrieve_results)
|
| 57 |
if len(check_arxiv_result) == 0:
|
| 58 |
is_arxiv_available = False
|
| 59 |
print("Arxiv search not working, switching to default search ...")
|
|
|
|
| 100 |
def get_rag(message):
|
| 101 |
return get_references(message, RAG)
|
| 102 |
|
| 103 |
+
def SaveResponseAndRead(result):
|
| 104 |
+
documentHTML5='''
|
| 105 |
+
<!DOCTYPE html>
|
| 106 |
+
<html>
|
| 107 |
+
<head>
|
| 108 |
+
<title>Read It Aloud</title>
|
| 109 |
+
<script type="text/javascript">
|
| 110 |
+
function readAloud() {
|
| 111 |
+
const text = document.getElementById("textArea").value;
|
| 112 |
+
const speech = new SpeechSynthesisUtterance(text);
|
| 113 |
+
window.speechSynthesis.speak(speech);
|
| 114 |
+
}
|
| 115 |
+
</script>
|
| 116 |
+
</head>
|
| 117 |
+
<body>
|
| 118 |
+
<h1>🔊 Read It Aloud</h1>
|
| 119 |
+
<textarea id="textArea" rows="10" cols="80">
|
| 120 |
+
'''
|
| 121 |
+
documentHTML5 = documentHTML5 + result
|
| 122 |
+
documentHTML5 = documentHTML5 + '''
|
| 123 |
+
</textarea>
|
| 124 |
+
<br>
|
| 125 |
+
<button onclick="readAloud()">🔊 Read Aloud</button>
|
| 126 |
+
</body>
|
| 127 |
+
</html>
|
| 128 |
+
'''
|
| 129 |
+
gr.HTML(documentHTML5)
|
| 130 |
+
|
| 131 |
+
|
| 132 |
with gr.Blocks(theme = gr.themes.Soft()) as demo:
|
| 133 |
header = gr.Markdown(header_text)
|
| 134 |
|
|
|
|
| 191 |
else:
|
| 192 |
return model_disabled_text
|
| 193 |
|
| 194 |
+
client = InferenceClient(llm_model_picked)
|
| 195 |
try:
|
| 196 |
stream = client.text_generation(prompt, **generate_kwargs, stream=stream_outputs, details=False, return_full_text=False)
|
| 197 |
|
|
|
|
| 202 |
if stream_outputs:
|
| 203 |
for response in stream:
|
| 204 |
output += response
|
| 205 |
+
SaveResponseAndRead(response)
|
| 206 |
yield output
|
| 207 |
return output
|
| 208 |
else:
|