Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# from transformers import AutoModelForCausalLM, AutoTokenizer
|
2 |
+
|
3 |
+
!pip install --no-cache-dir transformers sentencepiece
|
4 |
+
|
5 |
+
import time
|
6 |
+
import datetime
|
7 |
+
|
8 |
+
import streamlit as st
|
9 |
+
|
10 |
+
question = "Name the planets in the solar system? A: "
|
11 |
+
question = "Quais são os planetas do sistema solar?"
|
12 |
+
question = "Qual é o maior planeta do sistema solar?"
|
13 |
+
|
14 |
+
before = datetime.datetime.now()
|
15 |
+
|
16 |
+
from transformers import AutoTokenizer, XGLMModel
|
17 |
+
import torch
|
18 |
+
|
19 |
+
prompt = "Question: Qual é o maior planeta do sistema solar ?"
|
20 |
+
tokenizer = AutoTokenizer.from_pretrained("facebook/xglm-564M", use_fast=False)
|
21 |
+
model = XGLMModel.from_pretrained("facebook/xglm-564M")
|
22 |
+
|
23 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
24 |
+
outputs = model(**inputs, labels=inputs["input_ids"])
|
25 |
+
|
26 |
+
last_hidden_states = outputs.last_hidden_state
|
27 |
+
|
28 |
+
output = last_hidden_states
|
29 |
+
|
30 |
+
output = tokenizer.batch_decode(output, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
|
31 |
+
|
32 |
+
with st.container():
|
33 |
+
st.write('\n\n')
|
34 |
+
st.write('LLM-LANAChat')
|
35 |
+
st.write('\n\n' + output)
|
36 |
+
|
37 |
+
print('saida gerada.')
|
38 |
+
print('\n\n')
|
39 |
+
|
40 |
+
after = datetime.datetime.now()
|
41 |
+
current_time = (after - before) # .strftime("%H:%M:%S")
|
42 |
+
print("\nTime Elapsed: ", current_time)
|
43 |
+
st.write("\nTime Elapsed: ", current_time)
|