Delete app.py
Browse files
app.py
DELETED
@@ -1,55 +0,0 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
import torch
|
3 |
-
from tqdm import tqdm
|
4 |
-
from peft import PeftModel, PeftConfig
|
5 |
-
from transformers import AutoModelForSeq2SeqLM
|
6 |
-
from transformers import AutoTokenizer
|
7 |
-
|
8 |
-
config = PeftConfig.from_pretrained("NursNurs/T5ForReverseDictionary")
|
9 |
-
model = AutoModelForSeq2SeqLM.from_pretrained("google/flan-t5-large")
|
10 |
-
model = PeftModel.from_pretrained(model, "NursNurs/T5ForReverseDictionary")
|
11 |
-
|
12 |
-
tokenizer = AutoTokenizer.from_pretrained("google/flan-t5-large")
|
13 |
-
|
14 |
-
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
15 |
-
|
16 |
-
def return_top_k(sentence, k=10):
|
17 |
-
|
18 |
-
inputs = [f"Descripton : {sentence}. Word : "]
|
19 |
-
|
20 |
-
inputs = tokenizer(
|
21 |
-
inputs,
|
22 |
-
padding=True, truncation=True,
|
23 |
-
return_tensors="pt",
|
24 |
-
)
|
25 |
-
|
26 |
-
|
27 |
-
model.to(device)
|
28 |
-
|
29 |
-
with torch.no_grad():
|
30 |
-
inputs = {k: v.to(device) for k, v in inputs.items()}
|
31 |
-
output_sequences = model.generate(input_ids=inputs["input_ids"], max_new_tokens=10, num_beams=k, num_return_sequences=k, #max_length=3,
|
32 |
-
top_p = 50, output_scores=True, return_dict_in_generate=True) #repetition_penalty=10000.0
|
33 |
-
#print("output_sequences", output_sequences)
|
34 |
-
logits = output_sequences['sequences_scores'].clone().detach()
|
35 |
-
decoded_probabilities = torch.softmax(logits, dim=0)
|
36 |
-
|
37 |
-
|
38 |
-
#all word predictions
|
39 |
-
predictions = [tokenizer.decode(tokens, skip_special_tokens=True) for tokens in output_sequences['sequences']]
|
40 |
-
probabilities = [round(float(prob), 2) for prob in decoded_probabilities]
|
41 |
-
|
42 |
-
return predictions
|
43 |
-
|
44 |
-
|
45 |
-
st.title("You name it!")
|
46 |
-
|
47 |
-
# adding the text that will show in the text box as default
|
48 |
-
default_value = "Type the description of the word you have in mind!"
|
49 |
-
|
50 |
-
sent = st.text_area("Text", default_value, height = 275)
|
51 |
-
|
52 |
-
result = return_top_k(sent)
|
53 |
-
st.write("Here are my guesses about your word:")
|
54 |
-
st.write(result)
|
55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|