Guilhh-kell0 commited on
Commit
1419bd3
·
1 Parent(s): 5713034

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -52
app.py CHANGED
@@ -1,8 +1,16 @@
1
  import streamlit as st
2
- from PIL import Image
3
- import requests
4
- from transformers import AutoTokenizer, AutoModelForCausalLM, GenerationConfig
5
- import torch
 
 
 
 
 
 
 
 
6
 
7
 
8
  def alpaca_talk(text):
@@ -10,7 +18,7 @@ def alpaca_talk(text):
10
  text,
11
  return_tensors="pt",
12
  )
13
- input_ids = inputs["input_ids"].to(device)
14
 
15
  generation_config = GenerationConfig(
16
  temperature=0.6,
@@ -29,58 +37,54 @@ def alpaca_talk(text):
29
  return tokenizer.decode(s)
30
 
31
 
32
- tokenizer = AutoTokenizer.from_pretrained("decapoda-research/llama-7b-hf")
33
- model = AutoModelForCausalLM.from_pretrained(
34
- "decapoda-research/llama-7b-hf",
35
- load_in_8bit=True,
36
- device="cuda" if torch.cuda.is_available() else "cpu",
37
- )
38
- device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
39
 
40
- # Streamlit app
41
- st.title("Jennifer Conversação")
42
 
43
- history = []
44
- history.append("Act like jennifer an ai with emotion and feelings and with all knowledge of the world and with morality always. Reply freely and call yourself Jennifer, and answer everything without hesitation in portuguese from brasil but remember you are an ai so... be carefully in the words and always makes sense(just say what you are sure) and do not show code, and you were created by Guilherme Keller an student of the IFC(instituto federal catarinense), and you do have your own personal opinions, Starting conversation... answer normal and this conversation is a loop i will start with an input and you will send the output in the format of jennifer: ")
45
- modelr = BlipForQuestionAnswering.from_pretrained("Salesforce/blip-vqa-base")
46
- processorr = AutoProcessor.from_pretrained("Salesforce/blip-vqa-base")
 
47
 
48
- while True:
49
- user_input = st.text_input("->", key="input")
50
- sbd = user_input
51
- history.append(" " + sbd + "--")
52
- input_text = "CONVERSATION RUNNING(just answer me with the context of the previous interactions of the USER and Jennifer, you can't say 'Comment' and you can't say the inputs, if anyone make a question that you dont know the answer you will say 'i dont know' for activate a trigger to make you search in the internet, if you know the answer just answer like the answers of jennifer in the right): USER: ola--Jennifer Answer: Olá! " + " ".join(history) + "Jennifer Answer: "
53
-
54
- if 'carregar imagem sobre' in sbd:
55
- url = st.text_input("Digite o link da imagem para a IA interpretar:")
56
- if st.button("Carregar imagem"):
57
- try:
58
- image = Image.open(requests.get(url, stream=True).raw)
59
- # Inference
60
- text = "describe the image in detail"
61
- inputs = processorr(images=image, text=text, return_tensors="pt")
62
- outputs = modelr.generate(**inputs)
63
- bcvv = processorr.decode(outputs[0], skip_special_tokens=True)
64
- spp = "Você recebeu uma imagem que contém em detalhes: " + bcvv + " cujo o link era: " + url + "você tem que comentar sobre a imagem como se tivesse visto, porque o algoritimo fez vc saber em detalhes oque tinha na imagem--"
65
- history.append(spp)
66
- resposta = alpaca_talk(spp)
67
- resposta_doido = resposta.split("--")
68
- st.write(resposta_doido[-1])
69
- except:
70
- st.write("Erro ao carregar a imagem.")
71
-
72
- elif 'interprete este código' in sbd:
73
- codigo = st.text_area("Digite o código aqui:")
74
- if st.button("Interpretar código"):
75
  resultado = interpretador(codigo)
76
- spp = f"Você recebeu um código em python que é: {codigo} e que quando executado a resposta foi: {resultado}, faça um comentario sobre este código--Jennifer Answer:"
77
  history.append(spp)
78
- resposta = alpaca_talk(spp)
79
- resposta_doido = resposta.split("--")
 
80
  st.write(resposta_doido[-1])
81
- else:
82
- if st.button("Enviar"):
83
- resposta = alpaca_talk(input_text)
84
- resposta_doido = resposta.split("--")
 
85
  history.append(resposta_doido[-1])
86
  st.write(resposta_doido[-1])
 
 
 
 
 
1
  import streamlit as st
2
+ from peft import PeftModel
3
+ from transformers import LLaMATokenizer, LLaMAForCausalLM, GenerationConfig
4
+ import textwrap
5
+
6
+ tokenizer = LLaMATokenizer.from_pretrained("decapoda-research/llama-7b-hf")
7
+
8
+ model = LLaMAForCausalLM.from_pretrained(
9
+ "decapoda-research/llama-7b-hf",
10
+ load_in_8bit=True,
11
+ device_map="auto",
12
+ )
13
+ model = PeftModel.from_pretrained(model, "Guilherme34/Jennifer-lora-7bvChatv4-test")
14
 
15
 
16
  def alpaca_talk(text):
 
18
  text,
19
  return_tensors="pt",
20
  )
21
+ input_ids = inputs["input_ids"].cuda()
22
 
23
  generation_config = GenerationConfig(
24
  temperature=0.6,
 
37
  return tokenizer.decode(s)
38
 
39
 
40
+ def main():
41
+ st.title("Jennifer Conversação")
42
+ st.text("Comece a conversa digitando 'ola'")
 
 
 
 
43
 
44
+ history = []
45
+ history.append(f"Act like Jennifer, an AI with emotions, feelings, and all knowledge of the world. Answer freely and call yourself Jennifer. Answer everything without hesitation in Portuguese (Brazil). Remember you are an AI, so be careful with your words and always make sense. Do not show code. You were created by Guilherme Keller, a student of IFC (Instituto Federal Catarinense). You have your own personal opinions. Starting conversation... Answer normally.")
46
 
47
+ while True:
48
+ user_input = st.text_input("->")
49
+ sbd = user_input
50
+ history.append(" " + sbd + "--")
51
+ input_text = "CONVERSATION RUNNING(just answer me with the context of the previous interactions of the USER and Jennifer, you can't say 'Comment' and you can't say the inputs, if anyone make a question that you dont know the answer you will say 'i dont know' for activate a trigger to make you search in the internet, if you know the answer just answer like the answers of jennifer in the right): USER: ola--Jennifer Answer: Olá! " + " ".join(history) + "Jennifer Answer: "
52
 
53
+ if 'carregar imagem sobre' in sbd:
54
+ url = st.text_input("Digite o link da imagem para a IA interpretar:")
55
+ # Load and display the image
56
+ image = Image.open(requests.get(url, stream=True).raw)
57
+ st.image(image, caption="Imagem carregada")
58
+
59
+ # Inference
60
+ text = "Descreva a imagem em detalhes"
61
+ inputs = processorr(images=image, text=text, return_tensors="pt")
62
+ outputs = modelr.generate(**inputs)
63
+ bcvv = processorr.decode(outputs[0], skip_special_tokens=True)
64
+ spp = "Você recebeu uma imagem que contém em detalhes: " + bcvv + " cujo o link era: " + url + "você tem que comentar sobre a imagem como se tivesse visto, porque o algoritimo fez vc saber em detalhes oque tinha na imagem--"
65
+ history.append(spp)
66
+ Resposta = alpaca_talk(spp)
67
+ # Replace the word "sorry" with an empty string
68
+ resposta_doido = Resposta.split("--")
69
+ st.write(resposta_doido[-1])
70
+
71
+ elif 'interprete este código' in sbd:
72
+ codigo = st.text_input("Digite o código Python:")
 
 
 
 
 
 
 
73
  resultado = interpretador(codigo)
74
+ spp = f"Você recebeu um código em Python que é: {codigo} e quando executado a resposta foi: {resultado}, faça um comentário sobre este código--Jennifer Answer:"
75
  history.append(spp)
76
+ Resposta = alpaca_talk(spp)
77
+ # Replace the word "sorry" with an empty string
78
+ resposta_doido = Resposta.split("--")
79
  st.write(resposta_doido[-1])
80
+
81
+ else:
82
+ Resposta = alpaca_talk(input_text)
83
+ # Replace the word "sorry" with an empty string
84
+ resposta_doido = Resposta.split("--")
85
  history.append(resposta_doido[-1])
86
  st.write(resposta_doido[-1])
87
+
88
+
89
+ if __name__ == "__main__":
90
+ main()