Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #54

Merged
merged 23 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
95a737c
header improvement
jonasgabriel18 Jun 11, 2024
c779c55
csv pagination
jonasgabriel18 Jun 11, 2024
1dedc5b
button hovers fixed
jonasgabriel18 Jun 11, 2024
7722dd9
add backend dependencies to README
GiseleBr678 Jun 13, 2024
a03f9f1
classify button same size as others
jonasgabriel18 Jun 13, 2024
81d817d
remove early stopping and added notification on training completed
jonasgabriel18 Jun 13, 2024
2f9e51a
loading animation on backend availability
jonasgabriel18 Jun 15, 2024
65b6cc6
loading clip on classify button
jonasgabriel18 Jun 15, 2024
e264aa0
CI: bumps version to 0.3.0 [skip ci]
gh-action-bump-version Jun 17, 2024
681a47b
Merge branch 'develop' into front/small-changes
jonasgabriel18 Jun 17, 2024
f34e958
Merge pull request #52 from TailUFPB/front/small-changes
jonasgabriel18 Jun 17, 2024
72f520b
CI: bumps version to 0.3.1 [skip ci]
gh-action-bump-version Jun 17, 2024
456436b
Add app.spec
cmaloney111 Jun 17, 2024
7cc0407
Change package version
cmaloney111 Jun 17, 2024
3338489
CI: bumps version to 0.2.5 [skip ci]
gh-action-bump-version Jun 17, 2024
26b7f58
corrections
jonasgabriel18 Jun 17, 2024
f76c0b4
Merge pull request #53 from TailUFPB/front/small-changes
jonasgabriel18 Jun 17, 2024
546070a
CI: bumps version to 0.2.6 [skip ci]
gh-action-bump-version Jun 17, 2024
ffbd3d8
Update develop.yml
cmaloney111 Jun 17, 2024
52bb393
CI: bumps version to 0.2.7 [skip ci]
gh-action-bump-version Jun 17, 2024
8c7423f
Final fixes to chatbot and toast
cmaloney111 Jun 17, 2024
f6d97b2
CI: bumps version to 0.2.8 [skip ci]
gh-action-bump-version Jun 17, 2024
a31b388
Merge branch 'main' into develop
cmaloney111 Jun 17, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/develop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ jobs:
run: pip install -r api/requirements.txt pyinstaller==6.6.0

- name: Build flask exe
run: pyinstaller --name app --onefile --console api/app.py --hidden-import=tiktoken_ext.openai_public --hidden-import=tiktoken_ext

run: pyinstaller api/app.spec
- name: Install dependencies
run: npm install

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ jobs:
run: pip install -r api/requirements.txt pyinstaller==6.6.0

- name: Build flask exe
run: pyinstaller --name app --onefile --console api/app.py --hidden-import=tiktoken_ext.openai_public --hidden-import=tiktoken_ext
run: pyinstaller app.spec

- name: Install dependencies
run: npm install
Expand Down
32 changes: 22 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,35 @@
# LinguifAI

Projeto NLP 2 - 2023.2

## Tecnologias utilizadas:

O projeto utiliza das seguintes tecnologias e ferramentas:

### Front-End
* React
* React-Router
* Axios
* ElectronJs
* Tailwind

- React
- React-Router
- Axios
- ElectronJs
- Tailwind

### Back-End
* Python
* Flask

- Python
- Flask

## Como rodar a aplicação:

Primeiramente, instale as depencencias:
Primeiramente, instale as dependências:

Dependências do back-end:

```bash
pip install -r api/requirements.txt
```

Dependências do front-end:

```bash
yarn
Expand Down Expand Up @@ -48,6 +60,6 @@ npm run electron
- [x] Abrir CSV
- [x] Exibir Preview de N linhas do CSV
- [x] Escolher colunas de entrada
- [X] Selecionar classificador e enviar dados
- [x] Selecionar classificador e enviar dados
- [x] Exibir resultado do classificador
- [x] Exportar resultado em csv?
- [x] Exportar resultado em csv?
2 changes: 1 addition & 1 deletion api/Neural_Network2.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ def create_and_train_rnn_model(df, name, epochs = 10, batch_size = 32, learning_

if len(valid_losses) > 2 and all(valid_loss >= loss for loss in valid_losses[-3:]):
print('Stopping early due to lack of improvement in validation loss.')
break
# break

train_losses.append(train_loss)
valid_losses.append(valid_loss)
Expand Down
78 changes: 22 additions & 56 deletions api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ def chat():
chat_history = data.get('history', [])
api_key = data.get('apikey')


if df is not None:

print(df.head(1))
documents = split_dataframe_into_documents(df)

embeddings = OpenAIEmbeddings(api_key=api_key)
Expand All @@ -74,27 +77,24 @@ def chat():

return jsonify(reply=bot_reply)
else:
print("No df")
return jsonify(reply="No data available."), 400

# messages = [{"role": "system", "content": "You are a helpful assistant."}]
# for msg in chat_history:
# messages.append({"role": "user" if msg['origin'] == 'user' else "assistant", "content": msg['text']})
# messages.append({"role": "user", "content": user_message})

# try:
# client = openai.OpenAI(api_key = api_key)
# response = client.chat.completions.create(
# model="gpt-3.5-turbo",
# messages=messages,
# max_tokens=200
# )
# bot_reply = response.choices[0].message.content.strip()

# return jsonify(reply=bot_reply)
# except Exception as e:
# print(f"Error: {e}")
# return jsonify(reply="Desculpe, ocorreu um erro ao processar sua mensagem."), 500
messages = [{"role": "system", "content": "You are a helpful assistant."}]
for msg in chat_history:
messages.append({"role": "user" if msg['origin'] == 'user' else "assistant", "content": msg['text']})
messages.append({"role": "user", "content": user_message})

try:
client = openai.OpenAI(api_key = api_key)
response = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=messages,
max_tokens=200
)
bot_reply = response.choices[0].message.content.strip()

return jsonify(reply=bot_reply)
except Exception as e:
print(f"Error: {e}")
return jsonify(reply="Desculpe, ocorreu um erro ao processar sua mensagem."), 500


def shutdown_server():
Expand All @@ -116,7 +116,7 @@ def receive_file():
if file.filename == '':
return jsonify({'error': 'No selected file'}), 400
if file:
df = pd.read_csv(file)
df = pd.read_csv(file, on_bad_lines='skip')
return jsonify({'message': 'File uploaded successfully'}), 200


Expand Down Expand Up @@ -282,40 +282,6 @@ def apikey():
return jsonify(reply="Desculpe, ocorreu um erro ao processar sua mensagem."), 500


# @app.route('/chat', methods=['POST'])
# def chat():
# global df
# if df is not None:
# # run rag
# print(df.head(1))
# else:
# print("No df")
# data = request.get_json()
# user_message = data.get('message')
# chat_history = data.get('history', [])
# api_key = data.get('apikey')

# messages = [{"role": "system", "content": "You are a helpful assistant."}]
# for msg in chat_history:
# messages.append({"role": "user" if msg['origin'] == 'user' else "assistant", "content": msg['text']})
# messages.append({"role": "user", "content": user_message})

# try:
# client = openai.OpenAI(api_key = api_key)
# response = client.chat.completions.create(
# model="gpt-3.5-turbo", # ou a gente poderia ver com gpt 4 mas por enquanto coloquei 3.5
# messages=messages,
# max_tokens=200
# )
# bot_reply = response.choices[0].message.content.strip()

# return jsonify(reply=bot_reply)
# except Exception as e:
# print(f"Error: {e}")
# return jsonify(reply="Desculpe, ocorreu um erro ao processar sua mensagem."), 500



if __name__ == '__main__':
training_progress = {
'training_progress': 0,
Expand Down
5 changes: 3 additions & 2 deletions api/app.spec
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

# -*- mode: python ; coding: utf-8 -*-

entry_point = 'app.py'
Expand All @@ -9,7 +10,7 @@ a = Analysis(
pathex=[],
binaries=[],
datas=[],
hiddenimports=[],
hiddenimports=['tiktoken_ext.openai_public', 'tiktoken_ext'],
hookspath=[],
hooksconfig={},
runtime_hooks=[],
Expand Down Expand Up @@ -48,4 +49,4 @@ coll = COLLECT(
upx=True,
upx_exclude=[],
name='app',
)
)
33 changes: 28 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"name": "Cameron",
"email": "[email protected]"
},
"version": "0.2.5",
"version": "0.2.8",
"main": "./public/electron.js",
"homepage": "./",
"private": true,
Expand All @@ -32,6 +32,8 @@
"react-papaparse": "^4.1.0",
"react-router-dom": "^6.15.0",
"react-scripts": "5.0.0",
"react-spinners": "^0.13.8",
"react-toastify": "^10.0.5",
"react-transition-group": "^4.4.5",
"serve": "^14.2.1",
"typescript": "^4.9.5"
Expand Down
11 changes: 6 additions & 5 deletions src/components/chatbot/chatbot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,22 @@ const ChatBot: React.FC = () => {
const errorMessage: Message = { text: "Desculpe, ocorreu um erro. Tente novamente.", origin: 'bot' };
setChatHistory(prevHistory => [...prevHistory, errorMessage]);
}

console.log(message)
setMessage("");
console.log(message)
};

const sendAPIKeyMessage = () => {
setChatHistory(prevHistory => [
...prevHistory,
{ text: "Olá! Eu sou o (LinguiTalk ou LinguaBot). Coloca a sua chave:", origin: 'bot' }
{ text: "Olá! Eu sou o LinguiTalk, um chatbot para lhe auxiliar na exploração dos seus dados! Primeiro, insira uma chave API válida do ChatGPT:", origin: 'bot' }
]);
};

const sendInitialMessage = () => {
setChatHistory(prevHistory => [
...prevHistory,
{ text: "Olá! Eu sou o (LinguiTalk ou LinguaBot). Como posso ajudar?", origin: 'bot' }
{ text: "Olá! Eu sou o LinguiTalk. Como posso ajudar?", origin: 'bot' }
]);
};

Expand Down Expand Up @@ -98,7 +99,7 @@ const ChatBot: React.FC = () => {
{isOpen && (
<div className="fixed bottom-20 right-4 bg-white border border-gray-300 shadow-lg rounded-lg w-80 flex flex-col max-h-[600px]">
<div className="bg-blue-500 text-white p-4 flex justify-between items-center">
<h2 className="text-lg">LinguiTalk ou LinguaBot</h2>
<h2 className="text-lg">LinguiTalk</h2>
<button
className="text-white hover:text-gray-200"
onClick={toggleChat}
Expand Down Expand Up @@ -130,7 +131,7 @@ const ChatBot: React.FC = () => {
value={message}
onChange={(e) => setMessage(e.target.value)}
onKeyPress={(e) => {
if (e.key === 'Enter') sendMessage();
if (e.key === 'Enter') sendMessage()
}}
/>
<button
Expand Down
Loading
Loading