import transformers import re from transformers import AutoConfig, AutoTokenizer, AutoModel, AutoModelForCausalLM from vllm import LLM, SamplingParams import torch import gradio as gr import json import os import shutil import requests import chromadb import pandas as pd from chromadb.config import Settings from chromadb.utils import embedding_functions # Define the device device = "cuda" if torch.cuda.is_available() else "cpu" model_name = "PleIAs/OCRonos" llm = LLM(model_name, max_model_len=8128) #CSS for references formatting css = """ .generation { margin-left:2em; margin-right:2em; size:1.2em; } :target { background-color: #CCF3DF; /* Change the text color to red */ } .source { float:left; max-width:17%; margin-left:2%; } .tooltip { position: relative; cursor: pointer; font-variant-position: super; color: #97999b; } .tooltip:hover::after { content: attr(data-text); position: absolute; left: 0; top: 120%; /* Adjust this value as needed to control the vertical spacing between the text and the tooltip */ white-space: pre-wrap; /* Allows the text to wrap */ width: 500px; /* Sets a fixed maximum width for the tooltip */ max-width: 500px; /* Ensures the tooltip does not exceed the maximum width */ z-index: 1; background-color: #f9f9f9; color: #000; border: 1px solid #ddd; border-radius: 5px; padding: 5px; display: block; box-shadow: 0 4px 8px rgba(0,0,0,0.1); /* Optional: Adds a subtle shadow for better visibility */ }""" #Curtesy of chatgpt # Class to encapsulate the Falcon chatbot class MistralChatBot: def __init__(self, system_prompt="Le dialogue suivant est une conversation"): self.system_prompt = system_prompt def predict(self, user_message): sampling_params = SamplingParams(temperature=0.9, top_p=0.95, max_tokens=4000, presence_penalty=0, stop=["#END#"]) detailed_prompt = correction = f"### TEXT ###\n{user_message}\n\n### CORRECTION ###\n" print(detailed_prompt) prompts = [detailed_prompt] outputs = llm.generate(prompts, sampling_params, use_tqdm = False) generated_text = outputs[0].outputs[0].text generated_text = '