Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -15,8 +15,44 @@ from langchain.chains import ConversationChain
|
|
15 |
from langchain.memory import ConversationBufferMemory
|
16 |
from langchain_community.llms import HuggingFaceEndpoint
|
17 |
import torch
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
-
api_token = os.getenv("HF_TOKEN")
|
20 |
|
21 |
list_llm = ["meta-llama/Meta-Llama-3-8B-Instruct", "mistralai/Mistral-7B-Instruct-v0.3"]
|
22 |
list_llm_simple = [os.path.basename(llm) for llm in list_llm]
|
|
|
15 |
from langchain.memory import ConversationBufferMemory
|
16 |
from langchain_community.llms import HuggingFaceEndpoint
|
17 |
import torch
|
18 |
+
import os
|
19 |
+
import sys
|
20 |
+
import getpass
|
21 |
+
|
22 |
+
def masked_input(prompt=''):
|
23 |
+
import sys
|
24 |
+
import tty
|
25 |
+
import termios
|
26 |
+
|
27 |
+
print(prompt, end='', flush=True)
|
28 |
+
fd = sys.stdin.fileno()
|
29 |
+
old_settings = termios.tcgetattr(fd)
|
30 |
+
try:
|
31 |
+
tty.setraw(fd)
|
32 |
+
password = ''
|
33 |
+
while True:
|
34 |
+
ch = sys.stdin.read(1)
|
35 |
+
if ch == '\n' or ch == '\r':
|
36 |
+
break
|
37 |
+
elif ch == '\x7f': # Handle backspace
|
38 |
+
if len(password) > 0:
|
39 |
+
password = password[:-1]
|
40 |
+
sys.stdout.write('\b \b')
|
41 |
+
else:
|
42 |
+
password += ch
|
43 |
+
sys.stdout.write('*')
|
44 |
+
sys.stdout.flush()
|
45 |
+
finally:
|
46 |
+
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
|
47 |
+
print() # For newline
|
48 |
+
return password
|
49 |
+
|
50 |
+
# Solicita ao usuário a chave API de forma segura
|
51 |
+
api_key = masked_input(prompt="Digite sua chave API: ")
|
52 |
+
os.environ["OPENAI_API_KEY"] = api_key
|
53 |
+
# Solicita ao usuário a chave API de forma segura
|
54 |
+
|
55 |
|
|
|
56 |
|
57 |
list_llm = ["meta-llama/Meta-Llama-3-8B-Instruct", "mistralai/Mistral-7B-Instruct-v0.3"]
|
58 |
list_llm_simple = [os.path.basename(llm) for llm in list_llm]
|