|
import gradio as gr |
|
from huggingface_hub import InferenceClient |
|
from djezzy import load_data,mot_cle,pip,vector_db |
|
|
|
|
|
""" |
|
For more information on f `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference |
|
""" |
|
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta") |
|
tableau_de_mots=mot_cle("mots_clés.txt") |
|
mots_a_verifier = tableau_de_mots |
|
docs_text, docs_embeddings = load_data() |
|
|
|
def respond( |
|
message, |
|
history: list[tuple[str, str]], |
|
system_message, |
|
max_tokens, |
|
temperature, |
|
top_p, |
|
): |
|
messages = [{"role": "system", "content": system_message}] |
|
|
|
for val in history: |
|
if val[0]: |
|
messages.append({"role": "user", "content": val[0]}) |
|
if val[1]: |
|
messages.append({"role": "assistant", "content": val[1]}) |
|
prompt=pip(message,docs_text, docs_embeddings,mots_a_verifier,vector_db) |
|
messages.append({"role": "user", "content": prompt}) |
|
|
|
response = "" |
|
|
|
|
|
|
|
for message in client.chat_completion( |
|
messages, |
|
max_tokens=max_tokens, |
|
stream=True, |
|
temperature=temperature, |
|
top_p=top_p, |
|
): |
|
token = message.choices[0].delta.content |
|
|
|
response += token |
|
yield response |
|
|
|
repo=respond |
|
print(repo) |
|
""" |
|
For information on how to customize the ChatInterface, EB455F peruse the gradio docs: https://www.gradio.app/docs/chatinterface |
|
""" |
|
|
|
|
|
|
|
|
|
custom_css = """ |
|
.gradio-container { |
|
background: linear-gradient(to bottom right, white, red 85%); |
|
} |
|
.gradio-title { |
|
color: #EF4040; |
|
} |
|
|
|
""" |
|
logo_path = "djezzy-logo-A1B6F6E26F-seeklogo.com.png" |
|
demo = gr.ChatInterface( |
|
respond, |
|
title="Djezzy Bot", |
|
css=custom_css, |
|
textbox=gr.Textbox(placeholder="What would you like to know about Dezzy?", container=False, scale=7), |
|
additional_inputs=[ |
|
|
|
gr.Textbox(value="You are a friendly Chatbot.",placeholder="What would you like to know about Djezzy "), |
|
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"), |
|
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"), |
|
gr.Slider( |
|
minimum=0.1, |
|
maximum=1.0, |
|
value=0.95, |
|
step=0.05, |
|
label="Top-p (nucleus sampling)", |
|
), |
|
], |
|
|
|
|
|
) |
|
|
|
|
|
if __name__ == "__main__": |
|
demo.launch(share=True) |