File size: 1,117 Bytes
695223e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
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
34
35
36
37
38
39
40
import time
import datetime

import streamlit as st

question = "Name the planets in the solar system? A: "
question = "Quais são os planetas do sistema solar?" 
question = "Qual é o maior planeta do sistema solar?" 

before = datetime.datetime.now()

from transformers import AutoTokenizer, XGLMModel
import torch

prompt = "Question: Qual é o maior planeta do sistema solar ?"
tokenizer = AutoTokenizer.from_pretrained("facebook/xglm-564M",  use_fast=False)
model = XGLMModel.from_pretrained("facebook/xglm-564M")

inputs = tokenizer(prompt, return_tensors="pt")
outputs = model(**inputs, labels=inputs["input_ids"])

last_hidden_states = outputs.last_hidden_state

output = last_hidden_states

output = tokenizer.batch_decode(output, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]

with st.container():
    st.write('\n\n')
    st.write('LLM-LANAChat')
    st.write('\n\n' + output)

print('saida gerada.')
print('\n\n')

after = datetime.datetime.now()
current_time = (after - before) # .strftime("%H:%M:%S")
print("\nTime Elapsed: ", current_time)
st.write("\nTime Elapsed: ", current_time)