Upload 7 files
Browse files- READM.md +60 -0
- ap.py +45 -0
- gitignore.txt +1 -0
- pyproject.toml.txt +12 -0
- python-version.txt +1 -0
- requirement.text +6 -0
- uv.lock.txt +0 -0
READM.md
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: Eliza com LLLM
|
| 3 |
+
emoji: 💬
|
| 4 |
+
colorFrom: yellow
|
| 5 |
+
colorTo: purple
|
| 6 |
+
sdk: gradio
|
| 7 |
+
sdk_version: 5.34.2
|
| 8 |
+
app_file: app.py
|
| 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
|
ap.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
|
| 3 |
+
import torch
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
model_name = "google/gemma-4-E2B-it"
|
| 7 |
+
|
| 8 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 9 |
+
|
| 10 |
+
model = AutoModelForCausalLM.from_pretrained(model_name,
|
| 11 |
+
torch_dtype=torch.float16,
|
| 12 |
+
device_map="auto")
|
| 13 |
+
|
| 14 |
+
pipe = pipeline("text-generation",
|
| 15 |
+
model=model_name,
|
| 16 |
+
tokenizer=tokenizer,
|
| 17 |
+
max_new_tokens=150,
|
| 18 |
+
temperature=0.7)
|
| 19 |
+
|
| 20 |
+
def generate_response(message, history):
|
| 21 |
+
messages = [
|
| 22 |
+
[
|
| 23 |
+
{
|
| 24 |
+
"role": "system",
|
| 25 |
+
"content": [{"type": "text",
|
| 26 |
+
"text": "Você é ELIZA, uma terapeuta que responde com empatia e faz perguntas para entender melhor o paciente."},]
|
| 27 |
+
},
|
| 28 |
+
{
|
| 29 |
+
"role": "user",
|
| 30 |
+
"content": [{"type": "text",
|
| 31 |
+
"text": message},]
|
| 32 |
+
},
|
| 33 |
+
],
|
| 34 |
+
]
|
| 35 |
+
|
| 36 |
+
response = pipe(messages)
|
| 37 |
+
return response[0][0]['generated_text'][2]['content']
|
| 38 |
+
|
| 39 |
+
demo = gr.ChatInterface(
|
| 40 |
+
generate_response,
|
| 41 |
+
title="ELIZA (com LLM)",
|
| 42 |
+
description="Compartilhe seus pensamentos e ELIZA irá ajudar você a refletir sobre eles."
|
| 43 |
+
)
|
| 44 |
+
|
| 45 |
+
demo.launch()
|
gitignore.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
.venv
|
pyproject.toml.txt
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[project]
|
| 2 |
+
name = "eliza-llm"
|
| 3 |
+
version = "0.1.0"
|
| 4 |
+
description = "Add your description here"
|
| 5 |
+
readme = "README.md"
|
| 6 |
+
requires-python = ">=3.11"
|
| 7 |
+
dependencies = [
|
| 8 |
+
"accelerate>=1.13.0",
|
| 9 |
+
"gradio>=6.14.0",
|
| 10 |
+
"torch>=2.11.0",
|
| 11 |
+
"transformers>=5.7.0",
|
| 12 |
+
]
|
python-version.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
3.11
|
requirement.text
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
huggingface_hub
|
| 2 |
+
transformers
|
| 3 |
+
accelerate
|
| 4 |
+
torch
|
| 5 |
+
groq
|
| 6 |
+
gradio
|
uv.lock.txt
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|