Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,53 +1,54 @@
|
|
1 |
import os
|
2 |
os.system('pip install transformers')
|
3 |
os.system('pip install datasets')
|
4 |
-
os.system('pip install gradio')
|
5 |
-
os.system('pip install minijinja')
|
6 |
-
os.system('pip install PyMuPDF')
|
7 |
|
8 |
import gradio as gr
|
9 |
from huggingface_hub import InferenceClient
|
10 |
from transformers import pipeline
|
11 |
from datasets import load_dataset
|
12 |
-
import fitz # PyMuPDF
|
13 |
-
|
14 |
-
client = InferenceClient()
|
15 |
|
16 |
dataset = load_dataset("ibunescu/qa_legal_dataset_train")
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
def chat_between_bots(system_message1, system_message2, max_tokens, temperature, top_p, history1, history2, shared_history, message):
|
27 |
-
response1, history1 = list(respond(message, history1, system_message1, max_tokens, temperature, top_p))[-1]
|
28 |
-
response2, history2 = list(respond(message, history2, system_message2, max_tokens, temperature, top_p))[-1]
|
29 |
-
|
30 |
-
return response1, response2, history1, history2, shared_history
|
31 |
|
32 |
-
def
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
|
39 |
-
def ask_about_pdf(pdf_text, question):
|
40 |
-
prompt = f"PDF Content: {pdf_text}\n\nQuestion: {question}\n\nAnswer:"
|
41 |
response = ""
|
|
|
42 |
for message in client.chat_completion(
|
43 |
-
|
44 |
-
|
45 |
-
max_tokens=512,
|
46 |
stream=True,
|
47 |
-
temperature=
|
48 |
-
top_p=
|
49 |
):
|
50 |
token = message.choices[0].delta.content
|
|
|
|
|
|
|
|
|
51 |
if token is not None:
|
52 |
response += token
|
53 |
return response
|
|
|
1 |
import os
|
2 |
os.system('pip install transformers')
|
3 |
os.system('pip install datasets')
|
|
|
|
|
|
|
4 |
|
5 |
import gradio as gr
|
6 |
from huggingface_hub import InferenceClient
|
7 |
from transformers import pipeline
|
8 |
from datasets import load_dataset
|
|
|
|
|
|
|
9 |
|
10 |
dataset = load_dataset("ibunescu/qa_legal_dataset_train")
|
11 |
|
12 |
+
# Use a pipeline as a high-level helper
|
13 |
+
pipe = pipeline("fill-mask", model="nlpaueb/legal-bert-base-uncased")
|
14 |
+
|
15 |
+
"""
|
16 |
+
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
|
17 |
+
"""
|
18 |
+
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
+
def respond(
|
21 |
+
message,
|
22 |
+
history: list[tuple[str, str]],
|
23 |
+
system_message,
|
24 |
+
max_tokens,
|
25 |
+
temperature,
|
26 |
+
top_p,
|
27 |
+
):
|
28 |
+
messages = [{"role": "system", "content": system_message}]
|
29 |
+
|
30 |
+
for val in history:
|
31 |
+
if val[0]:
|
32 |
+
messages.append({"role": "user", "content": val[0]})
|
33 |
+
if val[1]:
|
34 |
+
messages.append({"role": "assistant", "content": val[1]})
|
35 |
+
|
36 |
+
messages.append({"role": "user", "content": message})
|
37 |
|
|
|
|
|
38 |
response = ""
|
39 |
+
|
40 |
for message in client.chat_completion(
|
41 |
+
messages,
|
42 |
+
max_tokens=max_tokens,
|
|
|
43 |
stream=True,
|
44 |
+
temperature=temperature,
|
45 |
+
top_p=top_p,
|
46 |
):
|
47 |
token = message.choices[0].delta.content
|
48 |
+
|
49 |
+
response += token
|
50 |
+
yield response
|
51 |
+
token = message.choices[0].delta.content
|
52 |
if token is not None:
|
53 |
response += token
|
54 |
return response
|