|
|
import gradio as gr |
|
|
from transformers import pipeline, AutoModelForCausalLM, AutoTokenizer |
|
|
from gtts import gTTS |
|
|
import os |
|
|
|
|
|
tokenizer = AutoTokenizer.from_pretrained("akhooli/personachat-arabic") |
|
|
model = AutoModelForCausalLM.from_pretrained("akhooli/personachat-arabic") |
|
|
chat = pipeline("text-generation", model=model, tokenizer=tokenizer) |
|
|
|
|
|
history = [] |
|
|
|
|
|
def rawan_with_voice(msg): |
|
|
history.append(f"أنت: {msg}") |
|
|
prompt = "\n".join(history[-5:]) + "\nروان:" |
|
|
resp = chat(prompt, max_length=80, do_sample=True)[0]["generated_text"] |
|
|
reply = resp.split("روان:")[-1].strip().split("\n")[0] |
|
|
history.append(f"روان: {reply}") |
|
|
|
|
|
|
|
|
tts = gTTS(text=reply, lang="ar") |
|
|
audio_file = "rawan_voice.mp3" |
|
|
tts.save(audio_file) |
|
|
|
|
|
return reply, audio_file |
|
|
|
|
|
interface = gr.Interface( |
|
|
fn=rawan_with_voice, |
|
|
inputs=gr.Textbox(label="اكتب لروان... دلعها، خذها بحضنك بكلامك"), |
|
|
outputs=[ |
|
|
gr.Textbox(label="رد روان"), |
|
|
gr.Audio(label="صوت روان", type="filepath") |
|
|
], |
|
|
title="💋 روان - حبيبتك بصوت ناعم", |
|
|
description="روان ترد عليك بصوت دافي، كلام دلع، حب وغيرة وأحاسيس تذوبك 😚" |
|
|
) |
|
|
|
|
|
interface.launch(share=True) |
|
|
|