File size: 1,257 Bytes
cde44e0
7e8d37f
 
 
cde44e0
 
7e8d37f
 
 
 
 
 
 
 
 
 
 
 
 
 
cde44e0
 
 
 
7e8d37f
 
 
 
 
 
cde44e0
 
 
 
 
7e8d37f
 
cde44e0
7e8d37f
cde44e0
7e8d37f
cde44e0
7e8d37f
cde44e0
 
 
 
 
 
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import gradio as gr
import os
from langchain.llms import CTransformers
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch


MODEL_PATH = 'TheBloke/Mistral-7B-Instruct-v0.1-GGUF'

# Some basic configurations for the model
config = {
    "max_new_tokens": 1000,
    "context_length": 1000,
    "repetition_penalty": 1.1,
    "temperature": 0.5,
    "top_k": 50,
    "top_p": 0.9,
    "stream": True,
    "threads": int(os.cpu_count() / 2)
}

model_name = "mistralai/Mistral-7B-Instruct-v0.1"


# We use Langchain's CTransformers llm class to load our quantized model
llm = CTransformers(model=MODEL_PATH,
                    config=config)

# Tokenizer for Mistral-7B-Instruct from HuggingFace
tokenizer = AutoTokenizer.from_pretrained("mistralai/Mistral-7B-Instruct-v0.1")

def greet(input_text):
  question = input_text

  prompt = f"""<s>[INST] Le contexte est l'assurance maladie en France[/INST]
  {question}</s>
  [INST] Rédige un email courtois de réponse en français à la question [/INST]"""

  answer = llm(prompt)

  answer = answer.replace("</s>", "").replace("[Votre nom]", "").replace("[nom]", "")

  

  return answer

iface = gr.Interface(fn=greet, inputs=["text"],
                     outputs="text")
iface.launch()