Robadeldesouza commited on
Commit
2ab9a23
·
verified ·
1 Parent(s): 93ca302

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +18 -19
  2. requirements.txt +2 -6
app.py CHANGED
@@ -1,25 +1,24 @@
 
1
  import gradio as gr
2
- from transformers import pipeline
3
 
4
- # Carrega modelo StarCoder otimizado para geração de código
5
- generator = pipeline("text-generation", model="bigcode/starcoder", device=-1)
 
 
 
 
6
 
7
  def chat(message, history):
8
- history = history or []
9
- response = generator(message, max_new_tokens=200, do_sample=True, temperature=0.2)[0]["generated_text"]
10
- # Pega apenas a resposta após a mensagem do usuário
11
- response = response[len(message):].strip()
12
- history.append((message, response))
13
- return history, history
14
 
15
- with gr.Blocks(css="style.css") as demo:
16
- gr.Markdown("# 💬 StarCoder Chat\nDigite sua mensagem abaixo e veja a resposta:")
 
 
 
 
 
17
 
18
- chatbot = gr.Chatbot(elem_id="chatbot")
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
- gradio
2
- transformers
3
- torch
4
- sentencepiece
5
- huggingface-hub
6
- websockets
 
1
+ ctransformers
2
+ gradio