Spaces:
Configuration error
Configuration error
Update app.py
Browse files
app.py
CHANGED
@@ -1,40 +1,55 @@
|
|
1 |
-
import torch
|
2 |
import gradio as gr
|
3 |
-
from transformers import
|
4 |
-
|
5 |
-
|
6 |
-
WhisperTokenizer,
|
7 |
-
WhisperProcessor,
|
8 |
-
)
|
9 |
-
from peft import PeftModel, PeftConfig
|
10 |
|
11 |
-
peft_model_id = "Moustapha91/whisper-small-wolof"
|
12 |
-
language = "French"
|
13 |
-
task = "transcribe"
|
14 |
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
return text
|
31 |
-
|
32 |
-
iface = gr.Interface(
|
33 |
-
fn=transcribe,
|
34 |
-
inputs=gr.Audio(type="filepath"), # On supprime 'source' pour éviter l'erreur
|
35 |
-
outputs="text",
|
36 |
-
title="PEFT LoRA + Whisper Small Wolof",
|
37 |
-
description="Realtime demo for Wolof speech recognition using `PEFT-LoRA` fine-tuned Whisper Small model.",
|
38 |
)
|
39 |
|
40 |
-
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
3 |
+
from typing import List, Tuple
|
4 |
+
import torch
|
|
|
|
|
|
|
|
|
5 |
|
|
|
|
|
|
|
6 |
|
7 |
+
model_name = "Hawoly18/Adia_Llama3.1"
|
8 |
+
|
9 |
+
# Vérifier si un GPU est disponible
|
10 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
11 |
+
|
12 |
+
|
13 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
14 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
15 |
+
|
16 |
+
def respond(
|
17 |
+
message: str,
|
18 |
+
history: List[Tuple[str, str]],
|
19 |
+
system_message: str,
|
20 |
+
max_tokens: int,
|
21 |
+
temperature: float,
|
22 |
+
top_p: float,
|
23 |
+
) -> str:
|
24 |
+
|
25 |
+
prompt = system_message
|
26 |
+
for user_msg, assistant_msg in history:
|
27 |
+
prompt += f"\nUser: {user_msg}\nAssistant: {assistant_msg}"
|
28 |
+
prompt += f"\nUser: {message}\nAssistant:"
|
29 |
+
|
30 |
+
|
31 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
32 |
+
outputs = model.generate(
|
33 |
+
**inputs,
|
34 |
+
max_length=max_tokens,
|
35 |
+
temperature=temperature,
|
36 |
+
top_p=top_p,
|
37 |
+
do_sample=True,
|
38 |
+
)
|
39 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True).split("Assistant:")[-1].strip()
|
40 |
+
return response
|
41 |
+
|
42 |
|
43 |
+
demo = gr.ChatInterface(
|
44 |
+
respond,
|
45 |
+
additional_inputs=[
|
46 |
+
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
47 |
+
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
48 |
+
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"), # Fixed syntax error
|
49 |
+
gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)"),
|
50 |
+
],
|
51 |
+
title="Chatbot Interface"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
)
|
53 |
|
54 |
+
if __name__ == "__main__":
|
55 |
+
demo.launch()
|