Spaces:
Runtime error
Runtime error
vincentclaes
commited on
Commit
•
e72642d
1
Parent(s):
60e3b0a
add processing of webpage
Browse files- app.py +17 -37
- requirements.txt +7 -3
app.py
CHANGED
@@ -2,7 +2,7 @@ import torch
|
|
2 |
from peft import PeftModel
|
3 |
import transformers
|
4 |
import gradio as gr
|
5 |
-
|
6 |
assert (
|
7 |
"LlamaTokenizer" in transformers._import_structure["models.llama"]
|
8 |
), "LLaMA is now in HuggingFace's main branch.\nPlease reinstall it: pip uninstall transformers && pip install git+https://github.com/huggingface/transformers.git"
|
@@ -59,14 +59,14 @@ else:
|
|
59 |
|
60 |
def generate_prompt(instruction, input=None):
|
61 |
if input:
|
62 |
-
return f"""Below is an
|
63 |
### Instruction:
|
64 |
{instruction}
|
65 |
### Input:
|
66 |
{input}
|
67 |
### Response:"""
|
68 |
else:
|
69 |
-
return f"""Below is an
|
70 |
### Instruction:
|
71 |
{instruction}
|
72 |
### Response:"""
|
@@ -80,7 +80,7 @@ if torch.__version__ >= "2":
|
|
80 |
|
81 |
def evaluate(
|
82 |
instruction,
|
83 |
-
|
84 |
temperature=0.1,
|
85 |
top_p=0.75,
|
86 |
top_k=40,
|
@@ -88,7 +88,8 @@ def evaluate(
|
|
88 |
max_new_tokens=128,
|
89 |
**kwargs,
|
90 |
):
|
91 |
-
|
|
|
92 |
inputs = tokenizer(prompt, return_tensors="pt")
|
93 |
input_ids = inputs["input_ids"].to(device)
|
94 |
generation_config = GenerationConfig(
|
@@ -115,16 +116,16 @@ g = gr.Interface(
|
|
115 |
fn=evaluate,
|
116 |
inputs=[
|
117 |
gr.components.Textbox(
|
118 |
-
lines=2, label="
|
119 |
-
),
|
120 |
-
gr.components.Textbox(lines=2, label="Input", placeholder="none"),
|
121 |
-
gr.components.Slider(minimum=0, maximum=1, value=0.1, label="Temperature"),
|
122 |
-
gr.components.Slider(minimum=0, maximum=1, value=0.75, label="Top p"),
|
123 |
-
gr.components.Slider(minimum=0, maximum=100, step=1, value=40, label="Top k"),
|
124 |
-
gr.components.Slider(minimum=1, maximum=4, step=1, value=4, label="Beams"),
|
125 |
-
gr.components.Slider(
|
126 |
-
minimum=1, maximum=512, step=1, value=128, label="Max tokens"
|
127 |
),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
128 |
],
|
129 |
outputs=[
|
130 |
gr.inputs.Textbox(
|
@@ -132,29 +133,8 @@ g = gr.Interface(
|
|
132 |
label="Output",
|
133 |
)
|
134 |
],
|
135 |
-
title="
|
136 |
-
description="Alpaca-LoRA is a 7B-parameter LLaMA model finetuned to follow instructions. It is trained on the [Stanford Alpaca](https://github.com/tatsu-lab/stanford_alpaca) dataset and makes use of the Huggingface LLaMA implementation. For more information, please visit [the project's website](https://github.com/tloen/alpaca-lora).",
|
137 |
)
|
138 |
g.queue(concurrency_count=1)
|
139 |
g.launch()
|
140 |
-
|
141 |
-
# Old testing code follows.
|
142 |
-
|
143 |
-
"""
|
144 |
-
if __name__ == "__main__":
|
145 |
-
# testing code for readme
|
146 |
-
for instruction in [
|
147 |
-
"Tell me about alpacas.",
|
148 |
-
"Tell me about the president of Mexico in 2019.",
|
149 |
-
"Tell me about the king of France in 2019.",
|
150 |
-
"List all Canadian provinces in alphabetical order.",
|
151 |
-
"Write a Python program that prints the first 10 Fibonacci numbers.",
|
152 |
-
"Write a program that prints the numbers from 1 to 100. But for multiples of three print 'Fizz' instead of the number and for the multiples of five print 'Buzz'. For numbers which are multiples of both three and five print 'FizzBuzz'.",
|
153 |
-
"Tell me five words that rhyme with 'shock'.",
|
154 |
-
"Translate the sentence 'I have no mouth but I must scream' into Spanish.",
|
155 |
-
"Count up from 1 to 500.",
|
156 |
-
]:
|
157 |
-
print("Instruction:", instruction)
|
158 |
-
print("Response:", evaluate(instruction))
|
159 |
-
print()
|
160 |
-
"""
|
|
|
2 |
from peft import PeftModel
|
3 |
import transformers
|
4 |
import gradio as gr
|
5 |
+
from scrape_website import process_webpage
|
6 |
assert (
|
7 |
"LlamaTokenizer" in transformers._import_structure["models.llama"]
|
8 |
), "LLaMA is now in HuggingFace's main branch.\nPlease reinstall it: pip uninstall transformers && pip install git+https://github.com/huggingface/transformers.git"
|
|
|
59 |
|
60 |
def generate_prompt(instruction, input=None):
|
61 |
if input:
|
62 |
+
return f"""Below is an url that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
|
63 |
### Instruction:
|
64 |
{instruction}
|
65 |
### Input:
|
66 |
{input}
|
67 |
### Response:"""
|
68 |
else:
|
69 |
+
return f"""Below is an url that describes a task. Write a response that appropriately completes the request.
|
70 |
### Instruction:
|
71 |
{instruction}
|
72 |
### Response:"""
|
|
|
80 |
|
81 |
def evaluate(
|
82 |
instruction,
|
83 |
+
url,
|
84 |
temperature=0.1,
|
85 |
top_p=0.75,
|
86 |
top_k=40,
|
|
|
88 |
max_new_tokens=128,
|
89 |
**kwargs,
|
90 |
):
|
91 |
+
content = process_webpage(url=url)
|
92 |
+
prompt = generate_prompt(instruction, content)
|
93 |
inputs = tokenizer(prompt, return_tensors="pt")
|
94 |
input_ids = inputs["input_ids"].to(device)
|
95 |
generation_config = GenerationConfig(
|
|
|
116 |
fn=evaluate,
|
117 |
inputs=[
|
118 |
gr.components.Textbox(
|
119 |
+
lines=2, label="FAQ", placeholder="Ask me anything about this website?"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
120 |
),
|
121 |
+
gr.components.Textbox(lines=2, label="Website URL", placeholder="https://www.meet-drift.ai/"),
|
122 |
+
# gr.components.Slider(minimum=0, maximum=1, value=0.1, label="Temperature"),
|
123 |
+
# gr.components.Slider(minimum=0, maximum=1, value=0.75, label="Top p"),
|
124 |
+
# gr.components.Slider(minimum=0, maximum=100, step=1, value=40, label="Top k"),
|
125 |
+
# gr.components.Slider(minimum=1, maximum=4, step=1, value=4, label="Beams"),
|
126 |
+
# gr.components.Slider(
|
127 |
+
# minimum=1, maximum=512, step=1, value=128, label="Max tokens"
|
128 |
+
# ),
|
129 |
],
|
130 |
outputs=[
|
131 |
gr.inputs.Textbox(
|
|
|
133 |
label="Output",
|
134 |
)
|
135 |
],
|
136 |
+
title="FAQ A Website",
|
137 |
+
# description="Alpaca-LoRA is a 7B-parameter LLaMA model finetuned to follow instructions. It is trained on the [Stanford Alpaca](https://github.com/tatsu-lab/stanford_alpaca) dataset and makes use of the Huggingface LLaMA implementation. For more information, please visit [the project's website](https://github.com/tloen/alpaca-lora).",
|
138 |
)
|
139 |
g.queue(concurrency_count=1)
|
140 |
g.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
requirements.txt
CHANGED
@@ -1,6 +1,10 @@
|
|
1 |
beautifulsoup4
|
2 |
requests
|
3 |
-
|
4 |
-
|
5 |
-
|
|
|
|
|
|
|
|
|
6 |
gradio
|
|
|
1 |
beautifulsoup4
|
2 |
requests
|
3 |
+
datasets
|
4 |
+
loralib
|
5 |
+
sentencepiece
|
6 |
+
git+https://github.com/huggingface/transformers.git
|
7 |
+
accelerate
|
8 |
+
bitsandbytes
|
9 |
+
git+https://github.com/huggingface/peft.git
|
10 |
gradio
|