File size: 1,329 Bytes
03f13dc
8ff57ac
22d8a11
8ff57ac
22d8a11
 
 
 
 
8ff57ac
 
 
 
 
 
 
 
22d8a11
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import gradio as gr
from transformers import AutoModelForCausalLM

# Cargar el modelo desde Hugging Face
model_name = "TheBloke/mistral-ft-optimized-1227-GGUF"
model = AutoModelForCausalLM.from_pretrained(model_name)

# Funci贸n para generar respuestas del chatbot
def chat_with_model(input_text):
    # Convertir el texto de entrada en una lista de tokens usando la codificaci贸n utf-8 (b谩sica, sin tokenizador)
    inputs = input_text.encode('utf-8')
    
    # Generar respuesta (puede que necesites ajustes dependiendo del modelo, ya que el manejo sin tokenizador es limitado)
    outputs = model.generate(inputs, max_length=100, num_return_sequences=1)
    
    # Convertir la salida de nuevo a texto (asumiendo que el modelo devuelve un objeto de cadena binaria)
    response = outputs[0].decode('utf-8', errors='ignore')
    return response

# Crear la interfaz con Gradio
interface = gr.Interface(fn=chat_with_model, 
                         inputs="text", 
                         outputs="text", 
                         title="Chatbot con Mistral FT Optimized",
                         description="Un chatbot b谩sico utilizando el modelo Mistral FT Optimized 1227 en Hugging Face.",
                         examples=["Hola, 驴c贸mo est谩s?", "Cu茅ntame un chiste."])

# Lanzar la aplicaci贸n
interface.launch()