Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- app.py +18 -19
- requirements.txt +2 -6
app.py
CHANGED
|
@@ -1,25 +1,24 @@
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from transformers import pipeline
|
| 3 |
|
| 4 |
-
# Carrega
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
def chat(message, history):
|
| 8 |
-
|
| 9 |
-
response =
|
| 10 |
-
|
| 11 |
-
response = response[len(message):].strip()
|
| 12 |
-
history.append((message, response))
|
| 13 |
-
return history, history
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
-
|
| 19 |
-
msg = gr.Textbox(placeholder="Digite sua mensagem...")
|
| 20 |
-
clear = gr.Button("Limpar")
|
| 21 |
-
|
| 22 |
-
msg.submit(chat, [msg, chatbot], [chatbot, chatbot])
|
| 23 |
-
clear.click(lambda: None, None, chatbot)
|
| 24 |
-
|
| 25 |
-
demo.launch()
|
|
|
|
| 1 |
+
from ctransformers import AutoModelForCausalLM
|
| 2 |
import gradio as gr
|
|
|
|
| 3 |
|
| 4 |
+
# Carrega CodeLlama 7B Instruct quantizado (GGUF) direto do Hugging Face
|
| 5 |
+
llm = AutoModelForCausalLM.from_pretrained(
|
| 6 |
+
"TheBloke/CodeLlama-7B-Instruct-GGUF",
|
| 7 |
+
model_file="codellama-7b-instruct.Q4_K_M.gguf", # versão leve
|
| 8 |
+
model_type="llama"
|
| 9 |
+
)
|
| 10 |
|
| 11 |
def chat(message, history):
|
| 12 |
+
prompt = f"### Instrução:\n{message}\n### Resposta:\n"
|
| 13 |
+
response = llm(prompt, max_new_tokens=512)
|
| 14 |
+
return response
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
+
# Layout igual ao anterior (estilo chat)
|
| 17 |
+
iface = gr.ChatInterface(
|
| 18 |
+
fn=chat,
|
| 19 |
+
title="MEu ChatBot CodeLlama",
|
| 20 |
+
description="Assistente de Programação rodando no Hugging Face Spaces (CodeLlama-7B Instruct).",
|
| 21 |
+
theme="soft"
|
| 22 |
+
)
|
| 23 |
|
| 24 |
+
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
requirements.txt
CHANGED
|
@@ -1,6 +1,2 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
torch
|
| 4 |
-
sentencepiece
|
| 5 |
-
huggingface-hub
|
| 6 |
-
websockets
|
|
|
|
| 1 |
+
ctransformers
|
| 2 |
+
gradio
|
|
|
|
|
|
|
|
|
|
|
|