DR-Rakshitha
commited on
Commit
•
0010001
1
Parent(s):
251ca72
update app.py
Browse files
app.py
CHANGED
@@ -1,60 +1,48 @@
|
|
1 |
-
import os
|
2 |
-
import urllib.request
|
3 |
import gradio as gr
|
4 |
-
from
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
#
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
stop=["#"],
|
34 |
)
|
35 |
-
output_text = output["choices"][0]["text"].strip()
|
36 |
-
|
37 |
-
# Remove Prompt Echo from Generated Text
|
38 |
-
cleaned_output_text = output_text.replace(prompt, "")
|
39 |
-
return cleaned_output_text
|
40 |
|
|
|
|
|
41 |
|
42 |
-
|
|
|
|
|
43 |
|
44 |
-
examples = [
|
45 |
-
["What is the capital of France?", "The capital of France is Paris."],
|
46 |
-
[
|
47 |
-
"Who wrote the novel 'Pride and Prejudice'?",
|
48 |
-
"The novel 'Pride and Prejudice' was written by Jane Austen.",
|
49 |
-
],
|
50 |
-
["What is the square root of 64?", "The square root of 64 is 8."],
|
51 |
-
]
|
52 |
|
53 |
-
|
54 |
fn=generate_text,
|
55 |
-
inputs=
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
3 |
+
import torch
|
4 |
+
from gpt4all import GPT4All
|
5 |
+
|
6 |
+
model = GPT4All("wizardlm-13b-v1.1-superhot-8k.ggmlv3.q4_0.bin")
|
7 |
+
|
8 |
+
# model = AutoModelForCausalLM.from_pretrained(
|
9 |
+
# "tiiuae/falcon-7b-instruct",
|
10 |
+
# torch_dtype=torch.bfloat16,
|
11 |
+
# trust_remote_code=True,
|
12 |
+
# device_map="auto",
|
13 |
+
# low_cpu_mem_usage=True,
|
14 |
+
# )
|
15 |
+
# tokenizer = AutoTokenizer.from_pretrained("tiiuae/falcon-7b-instruct")
|
16 |
+
|
17 |
+
|
18 |
+
def generate_text(input_text):
|
19 |
+
# input_ids = tokenizer.encode(input_text, return_tensors="pt")
|
20 |
+
# attention_mask = torch.ones(input_ids.shape)
|
21 |
+
|
22 |
+
output = model.generate(
|
23 |
+
input_text
|
24 |
+
# input_ids,
|
25 |
+
# attention_mask=attention_mask,
|
26 |
+
# max_length=200,
|
27 |
+
# do_sample=True,
|
28 |
+
# top_k=10,
|
29 |
+
# num_return_sequences=1,
|
30 |
+
# eos_token_id=tokenizer.eos_token_id,
|
|
|
31 |
)
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
+
# output_text = tokenizer.decode(output[0], skip_special_tokens=True)
|
34 |
+
# print(output_text)
|
35 |
|
36 |
+
# Remove Prompt Echo from Generated Text
|
37 |
+
# cleaned_output_text = output_text.replace(input_text, "")
|
38 |
+
return output
|
39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
|
41 |
+
text_generation_interface = gr.Interface(
|
42 |
fn=generate_text,
|
43 |
+
inputs=[
|
44 |
+
gr.inputs.Textbox(label="Input Text"),
|
45 |
+
],
|
46 |
+
outputs=gr.inputs.Textbox(label="Generated Text"),
|
47 |
+
title="Falcon-7B Instruct",
|
48 |
+
).launch()
|