Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,13 +1,13 @@
|
|
| 1 |
-
from groq import Groq
|
| 2 |
import base64
|
| 3 |
import streamlit as st
|
| 4 |
import pandas as pd
|
| 5 |
import json
|
| 6 |
from datetime import datetime
|
| 7 |
-
|
|
|
|
| 8 |
import os
|
| 9 |
-
|
| 10 |
-
from
|
| 11 |
|
| 12 |
# Inicialização do cliente Groq
|
| 13 |
client = Groq(
|
|
@@ -17,12 +17,14 @@ client = Groq(
|
|
| 17 |
llava_model = 'llava-v1.5-7b-4096-preview'
|
| 18 |
llama31_model = 'llama-3.1-70b-versatile'
|
| 19 |
|
| 20 |
-
#
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
return base64.b64encode(image_file.read()).decode('utf-8')
|
| 24 |
|
| 25 |
-
#
|
|
|
|
|
|
|
|
|
|
| 26 |
def image_to_text(client, model, base64_image, prompt):
|
| 27 |
chat_completion = client.chat.completions.create(
|
| 28 |
messages=[
|
|
@@ -43,13 +45,13 @@ def image_to_text(client, model, base64_image, prompt):
|
|
| 43 |
)
|
| 44 |
return chat_completion.choices[0].message.content
|
| 45 |
|
| 46 |
-
#
|
| 47 |
def game_generation(client, image_description, age, support_level, stimulus_type):
|
| 48 |
chat_completion = client.chat.completions.create(
|
| 49 |
messages=[
|
| 50 |
{
|
| 51 |
"role": "system",
|
| 52 |
-
"content": f"Suggest a safe game for a child of {age} years old, with support level {support_level} and focus on {stimulus_type}. The game should use the object described in the image and should not use objects that are dangerous for children
|
| 53 |
},
|
| 54 |
{
|
| 55 |
"role": "user",
|
|
@@ -60,11 +62,21 @@ def game_generation(client, image_description, age, support_level, stimulus_type
|
|
| 60 |
)
|
| 61 |
return chat_completion.choices[0].message.content
|
| 62 |
|
| 63 |
-
# Função
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
def main():
|
| 65 |
st.image("autism.png", width=200)
|
| 66 |
st.title("PlayBot - Gerador de Brincadeiras", anchor="center")
|
| 67 |
-
st.write("Conheça o PlayBot, um assistente inteligente que gera brincadeiras
|
| 68 |
|
| 69 |
# Entrada de dados do usuário
|
| 70 |
idade = st.number_input("Idade da criança:", min_value=1, max_value=16, step=1)
|
|
@@ -86,22 +98,10 @@ def main():
|
|
| 86 |
game_description = game_generation(client, image_description, idade, nivel_suporte, tipo_estimulo)
|
| 87 |
st.write(game_description)
|
| 88 |
|
| 89 |
-
# Salvando dados no
|
| 90 |
-
|
| 91 |
-
"Idade": idade,
|
| 92 |
-
"Nível de Suporte": nivel_suporte,
|
| 93 |
-
"Tipo de Estimulo": tipo_estimulo
|
| 94 |
-
}
|
| 95 |
-
df = pd.DataFrame([data])
|
| 96 |
-
|
| 97 |
-
# Conexão com o banco de dados SQLite
|
| 98 |
-
engine = create_engine('sqlite:///dados_usuarios.db')
|
| 99 |
-
|
| 100 |
-
# Inserindo os dados na tabela 'usuarios'
|
| 101 |
-
df.to_sql('usuarios', con=engine, if_exists='append', index=False)
|
| 102 |
-
|
| 103 |
-
st.success("Dados registrados no banco de dados com sucesso.")
|
| 104 |
|
| 105 |
# Executar o app
|
| 106 |
if __name__ == "__main__":
|
| 107 |
main()
|
|
|
|
|
|
|
|
|
| 1 |
import base64
|
| 2 |
import streamlit as st
|
| 3 |
import pandas as pd
|
| 4 |
import json
|
| 5 |
from datetime import datetime
|
| 6 |
+
import firebase_admin
|
| 7 |
+
from firebase_admin import credentials, firestore
|
| 8 |
import os
|
| 9 |
+
|
| 10 |
+
from groq import Groq
|
| 11 |
|
| 12 |
# Inicialização do cliente Groq
|
| 13 |
client = Groq(
|
|
|
|
| 17 |
llava_model = 'llava-v1.5-7b-4096-preview'
|
| 18 |
llama31_model = 'llama-3.1-70b-versatile'
|
| 19 |
|
| 20 |
+
# 1. Inicializar o Firebase Admin SDK
|
| 21 |
+
cred = credentials.Certificate("playbot-f0897-firebase-adminsdk-uay8b-0c87a1f1d0.json") # Substitua pelo caminho correto
|
| 22 |
+
firebase_admin.initialize_app(cred)
|
|
|
|
| 23 |
|
| 24 |
+
# Conectar ao Firestore
|
| 25 |
+
db = firestore.client()
|
| 26 |
+
|
| 27 |
+
# 2. Função para converter imagem em texto
|
| 28 |
def image_to_text(client, model, base64_image, prompt):
|
| 29 |
chat_completion = client.chat.completions.create(
|
| 30 |
messages=[
|
|
|
|
| 45 |
)
|
| 46 |
return chat_completion.choices[0].message.content
|
| 47 |
|
| 48 |
+
# 3. Função para gerar uma brincadeira
|
| 49 |
def game_generation(client, image_description, age, support_level, stimulus_type):
|
| 50 |
chat_completion = client.chat.completions.create(
|
| 51 |
messages=[
|
| 52 |
{
|
| 53 |
"role": "system",
|
| 54 |
+
"content": f"Suggest a safe game for a child of {age} years old, with support level {support_level} and focus on {stimulus_type}. The game should use the object described in the image and should not use objects that are dangerous for children...",
|
| 55 |
},
|
| 56 |
{
|
| 57 |
"role": "user",
|
|
|
|
| 62 |
)
|
| 63 |
return chat_completion.choices[0].message.content
|
| 64 |
|
| 65 |
+
# 4. Função para salvar os dados no Firestore
|
| 66 |
+
def save_to_firestore(idade, nivel_suporte, tipo_estimulo):
|
| 67 |
+
doc_ref = db.collection('usuarios').add({
|
| 68 |
+
"Idade": idade,
|
| 69 |
+
"Nível de Suporte": nivel_suporte,
|
| 70 |
+
"Tipo de Estimulo": tipo_estimulo,
|
| 71 |
+
"datetime": datetime.now()
|
| 72 |
+
})
|
| 73 |
+
st.success("Dados registrados no Firebase Firestore com sucesso.")
|
| 74 |
+
|
| 75 |
+
# 5. Função principal do app Streamlit
|
| 76 |
def main():
|
| 77 |
st.image("autism.png", width=200)
|
| 78 |
st.title("PlayBot - Gerador de Brincadeiras", anchor="center")
|
| 79 |
+
st.write("Conheça o PlayBot, um assistente inteligente que gera brincadeiras...")
|
| 80 |
|
| 81 |
# Entrada de dados do usuário
|
| 82 |
idade = st.number_input("Idade da criança:", min_value=1, max_value=16, step=1)
|
|
|
|
| 98 |
game_description = game_generation(client, image_description, idade, nivel_suporte, tipo_estimulo)
|
| 99 |
st.write(game_description)
|
| 100 |
|
| 101 |
+
# Salvando dados no Firestore
|
| 102 |
+
save_to_firestore(idade, nivel_suporte, tipo_estimulo)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
|
| 104 |
# Executar o app
|
| 105 |
if __name__ == "__main__":
|
| 106 |
main()
|
| 107 |
+
|