ultima versao
Browse files- .gitignore +1 -0
- README.md +49 -1
- app.py +26 -28
- requirements.txt +5 -1
.gitignore
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
venv
|
README.md
CHANGED
@@ -9,4 +9,52 @@ app_file: app.py
|
|
9 |
pinned: false
|
10 |
---
|
11 |
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
pinned: false
|
10 |
---
|
11 |
|
12 |
+
# Eliza com LLM 💬
|
13 |
+
|
14 |
+
Um chatbot de exemplo utilizando [Gradio](https://gradio.app), [`huggingface_hub`](https://huggingface.co/docs/huggingface_hub/v0.22.2/en/index) e a [Hugging Face Inference API](https://huggingface.co/docs/api-inference/index).
|
15 |
+
|
16 |
+
## Descrição
|
17 |
+
|
18 |
+
Este projeto implementa um chatbot inspirado na clássica Eliza, mas utilizando modelos de linguagem modernos (LLMs) para respostas mais naturais e inteligentes. A interface é construída com Gradio, permitindo fácil interação via web.
|
19 |
+
|
20 |
+
## Funcionalidades
|
21 |
+
|
22 |
+
- Interface web simples e intuitiva
|
23 |
+
- Respostas geradas por modelos de linguagem avançados
|
24 |
+
- Integração com a API de inferência da Hugging Face
|
25 |
+
|
26 |
+
## Como executar
|
27 |
+
|
28 |
+
1. **Clone o repositório:**
|
29 |
+
```bash
|
30 |
+
git clone <URL_DO_REPOSITORIO>
|
31 |
+
cd eliza_llm
|
32 |
+
```
|
33 |
+
|
34 |
+
2. **Instale as dependências:**
|
35 |
+
```bash
|
36 |
+
pip install -r requirements.txt
|
37 |
+
```
|
38 |
+
|
39 |
+
3. **Execute o aplicativo:**
|
40 |
+
```bash
|
41 |
+
python app.py
|
42 |
+
```
|
43 |
+
|
44 |
+
4. Acesse a interface no navegador pelo endereço exibido no terminal (geralmente http://localhost:7860).
|
45 |
+
|
46 |
+
## Requisitos
|
47 |
+
|
48 |
+
- Python 3.8 ou superior
|
49 |
+
- Conta na Hugging Face (para uso da API, se necessário)
|
50 |
+
|
51 |
+
## Estrutura do Projeto
|
52 |
+
|
53 |
+
- `app.py`: Código principal do chatbot e da interface Gradio
|
54 |
+
- `requirements.txt`: Dependências do projeto
|
55 |
+
- `README.md`: Este arquivo
|
56 |
+
|
57 |
+
## Créditos
|
58 |
+
|
59 |
+
- Inspirado no chatbot Eliza
|
60 |
+
- Utiliza Gradio e Hugging Face
|
app.py
CHANGED
@@ -1,37 +1,35 @@
|
|
1 |
import gradio as gr
|
2 |
-
from
|
|
|
3 |
|
4 |
-
#
|
5 |
-
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
def generate_response(message, history):
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
"role": "user",
|
21 |
-
"content": message
|
22 |
-
}
|
23 |
-
],
|
24 |
-
model="mixtral-8x7b-32768", # ou outro modelo disponível no Groq
|
25 |
-
temperature=0.7,
|
26 |
-
max_tokens=150
|
27 |
-
)
|
28 |
-
|
29 |
-
# Retorna a resposta gerada
|
30 |
-
return chat_completion.choices[0].message.content
|
31 |
|
32 |
-
|
33 |
|
34 |
-
|
|
|
|
|
|
|
35 |
demo = gr.ChatInterface(
|
36 |
generate_response,
|
37 |
title="ELIZA Therapy Session",
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
|
3 |
+
import torch
|
4 |
|
5 |
+
# Carrega o modelo e o tokenizer localmente
|
6 |
+
model_name = "google/gemma-3-1b-it" # Substitua pelo caminho local se já baixou
|
7 |
+
|
8 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
9 |
+
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.float16, device_map="auto")
|
10 |
+
|
11 |
+
pipe = pipeline("text-generation", model=model, tokenizer=tokenizer, max_new_tokens=150, temperature=0.7)
|
12 |
|
13 |
def generate_response(message, history):
|
14 |
+
messages = [
|
15 |
+
[
|
16 |
+
{
|
17 |
+
"role": "system",
|
18 |
+
"content": [{"type": "text", "text": "Você é ELIZA, uma terapeuta que responde com empatia e faz perguntas para entender melhor o paciente."},]
|
19 |
+
},
|
20 |
+
{
|
21 |
+
"role": "user",
|
22 |
+
"content": [{"type": "text", "text": message},]
|
23 |
+
},
|
24 |
+
],
|
25 |
+
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
|
27 |
+
response = pipe(messages)
|
28 |
|
29 |
+
return response[0][0]['generated_text'][2]['content']
|
30 |
+
|
31 |
+
|
32 |
+
# Cria a interface Gradio
|
33 |
demo = gr.ChatInterface(
|
34 |
generate_response,
|
35 |
title="ELIZA Therapy Session",
|
requirements.txt
CHANGED
@@ -1,2 +1,6 @@
|
|
1 |
huggingface_hub==0.25.2
|
2 |
-
|
|
|
|
|
|
|
|
|
|
1 |
huggingface_hub==0.25.2
|
2 |
+
transformers
|
3 |
+
accelerate
|
4 |
+
torch
|
5 |
+
groq
|
6 |
+
gradio
|