Motazsh commited on
Commit
a1a0cae
·
verified ·
1 Parent(s): 510f49c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -3
app.py CHANGED
@@ -1,18 +1,37 @@
1
  import gradio as gr
2
  from transformers import pipeline, AutoModelForCausalLM, AutoTokenizer
 
 
3
 
4
  tokenizer = AutoTokenizer.from_pretrained("akhooli/personachat-arabic")
5
  model = AutoModelForCausalLM.from_pretrained("akhooli/personachat-arabic")
6
  chat = pipeline("text-generation", model=model, tokenizer=tokenizer)
7
 
8
  history = []
9
- def chat_rawan(msg):
 
10
  history.append(f"أنت: {msg}")
11
  prompt = "\n".join(history[-5:]) + "\nروان:"
12
  resp = chat(prompt, max_length=80, do_sample=True)[0]["generated_text"]
13
  reply = resp.split("روان:")[-1].strip().split("\n")[0]
14
  history.append(f"روان: {reply}")
15
- return reply
16
 
17
- interface = gr.Interface(chat_rawan, gr.Textbox(label="اكتب لروان"), gr.Textbox(label="روان ترد"))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  interface.launch(share=True)
 
1
  import gradio as gr
2
  from transformers import pipeline, AutoModelForCausalLM, AutoTokenizer
3
+ from gtts import gTTS
4
+ import os
5
 
6
  tokenizer = AutoTokenizer.from_pretrained("akhooli/personachat-arabic")
7
  model = AutoModelForCausalLM.from_pretrained("akhooli/personachat-arabic")
8
  chat = pipeline("text-generation", model=model, tokenizer=tokenizer)
9
 
10
  history = []
11
+
12
+ def rawan_with_voice(msg):
13
  history.append(f"أنت: {msg}")
14
  prompt = "\n".join(history[-5:]) + "\nروان:"
15
  resp = chat(prompt, max_length=80, do_sample=True)[0]["generated_text"]
16
  reply = resp.split("روان:")[-1].strip().split("\n")[0]
17
  history.append(f"روان: {reply}")
 
18
 
19
+ # توليد الصوت
20
+ tts = gTTS(text=reply, lang="ar")
21
+ audio_file = "rawan_voice.mp3"
22
+ tts.save(audio_file)
23
+
24
+ return reply, audio_file
25
+
26
+ interface = gr.Interface(
27
+ fn=rawan_with_voice,
28
+ inputs=gr.Textbox(label="اكتب لروان... دلعها، خذها بحضنك بكلامك"),
29
+ outputs=[
30
+ gr.Textbox(label="رد روان"),
31
+ gr.Audio(label="صوت روان", type="filepath")
32
+ ],
33
+ title="💋 روان - حبيبتك بصوت ناعم",
34
+ description="روان ترد عليك بصوت دافي، كلام دلع، حب وغيرة وأحاسيس تذوبك 😚"
35
+ )
36
+
37
  interface.launch(share=True)