File size: 4,079 Bytes
a8cbe33
c70166c
 
f01fe14
c70166c
a8cbe33
c70166c
a8cbe33
f01fe14
 
c70166c
f01fe14
c70166c
f01fe14
 
c70166c
 
 
f01fe14
9e10b64
 
c70166c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b7f6ba1
c70166c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9e10b64
c70166c
 
 
 
 
 
 
 
 
 
 
a8cbe33
 
f01fe14
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import gradio as gr
from transformers import pipeline
import tempfile
import edge_tts
import inflect

number_to_word = inflect.engine()

# Modèle de langue français
model = pipeline("text-generation", model="dbddv01/gpt2-french-small")

async def transcribe(audio):
    lang = "fr"
    # Supposons que vous avez déjà défini la fonction de transcription transcribe() dans votre code
    text = transcribe(audio)
    return text

async def respond(audio):
    user = await transcribe(audio)
    reply = model(user, max_length=50, num_return_sequences=1)[0]['generated_text']
    communicate = edge_tts.Communicate(reply)
    with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp_file:
        tmp_path = tmp_file.name
        await communicate.save(tmp_path)
    yield tmp_path

DESCRIPTION = """ # <center><b>JARVIS⚡</b></center>
        ### <center>A personal Assistant of Tony Stark for YOU
        ### <center>Voice Chat with your personal Assistant</center>
        """

MORE = """ ## TRY Other Models
        ### Instant Video: Create Amazing Videos in 5 Second -> https://huggingface.co/spaces/KingNish/Instant-Video
        ### Instant Image: 4k images in 5 Second -> https://huggingface.co/spaces/KingNish/Instant-Image
        """

FAST = """## Fastest Model"""

base_loaded = "mistralai/Mixtral-8x7B-Instruct-v0.1"

client1 = InferenceClient(base_loaded)

system_instructions1 = "<s>[SYSTEM] Répondez comme le vrai Jarvis JARVIS, fabriqué par 'Tony Stark'. La conversation doit être très courte, claire, amicale et concise. Le texte fourni est une demande de réponse spécifique de votre part, en tant qu'assistant virtuel. Il vous demande de fournir des réponses amicales comme si vous étiez le personnage Jarvis, créé par « Tony Stark ». On s'attend à ce que j'évite les présentations et que je réponde directement à la requête, en développant tous les aspects de la demande. En tant qu'assistant doté d'une IA, votre tâche consiste à générer des réponses qui semblent avoir été créées par l'utilisateur et non par un assistant doté d'une IA.[USER]"

async def generate1(prompt):
    generate_kwargs = dict(
        temperature=0.7,
        max_new_tokens=512,
        top_p=0.95,
        repetition_penalty=1,
        do_sample=False,
    )
    formatted_prompt = system_instructions1 + prompt + "[JARVIS]"
    stream = client1.text_generation(
        formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=True)
    output = ""
    for response in stream:
        if not response.token.text == "</s>":
            output += response.token.text

    communicate = edge_tts.Communicate(output)
    with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp_file:
        tmp_path = tmp_file.name
        await communicate.save(tmp_path)
    yield tmp_path

with gr.Blocks(css="style.css") as demo:    
    gr.Markdown(DESCRIPTION)
    with gr.Row():
        user_input = gr.Audio(label="Voice Chat (BETA)", type="filepath")
        output_audio = gr.Audio(label="JARVIS", type="filepath",
                        interactive=False,
                        autoplay=True,
                        elem_classes="audio")
    with gr.Row():
        translate_btn = gr.Button("Response")
        translate_btn.click(fn=respond, inputs=user_input,
                            outputs=output_audio, api_name=False)
    gr.Markdown(FAST)
    with gr.Row():
        user_input = gr.Textbox(label="Prompt", value="Qu'est-ce que Wikipedia")
        input_text = gr.Textbox(label="Input Text", elem_id="important")
        output_audio = gr.Audio(label="JARVIS", type="filepath",
                        interactive=False,
                        autoplay=True,
                        elem_classes="audio")
    with gr.Row():
        translate_btn = gr.Button("Response")
        translate_btn.click(fn=generate1, inputs=user_input,
                            outputs=output_audio, api_name="translate")  

gr.Markdown(MORE)

if __name__ == "__main__":
    demo.queue(max_size=200).launch()