Azdeen commited on
Commit
996d96b
·
verified ·
1 Parent(s): 31c7c2e

import gradio as gr

Browse files

import requests

# مفاتيح و Endpoints
AZURE_API_KEY = "4AwsIf87cyBIgaJVsy0phWUQdZFcbrJxpQBDQNzL4xjcP2MFzrrYJQQJ99BIACHYHv6XJ3w3AAAAACOGYrzM"
AZURE_CHAT_ENDPOINT = "https://lahja-dev-resource.cognitiveservices.azure.com/openai/deployments/gpt-4o/chat/completions?api-version=2025-01-01-preview"
AZURE_TTS_ENDPOINT = "https://lahja-dev-resource.cognitiveservices.azure.com/openai/deployments/LAHJA-V1/audio/speech?api-version=2025-03-01-preview"

# دالة توليد رد GPT
def chat_with_gpt(text):
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {AZURE_API_KEY}"
}
data = {
"messages": [{"role": "user", "content": text}],
"max_tokens": 4096,
"temperature": 1,
"top_p": 1,
"model": "gpt-4o"
}
response = requests.post(AZURE_CHAT_ENDPOINT, json=data, headers=headers)
if response.status_code == 200:
return response.json()["choices"][0]["message"]["content"]
else:
return f"Error: {response.status_code}\n{response.text}"

# دالة تحويل النص لصوت
def text_to_speech(text, voice, speed):
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {AZURE_API_KEY}"
}
data = {
"model": "LAHJA-V1",
"input": text,
"voice": voice,
"speed": speed
}
response = requests.post(AZURE_TTS_ENDPOINT, json=data, headers=headers)
if response.status_code == 200:
audio_file = "output_audio.wav"
with open(audio_file, "wb") as f:
f.write(response.content)
return audio_file
else:
return f"Error: {response.status_code}\n{response.text}"

# دالة رئيسية للواجهة
def chat_and_speak(user_input, voice, speed):
reply = chat_with_gpt(user_input)
audio_file = text_to_speech(reply, voice, speed)
return reply, audio_file

# واجهة Gradio
iface = gr.Interface(
fn=chat_and_speak,
inputs=[
gr.Textbox(lines=5, placeholder="اكتب سؤالك هنا...", label="نص المستخدم"),
gr.Dropdown(choices=["alloy"], value="alloy", label="اختر الصوت"),
gr.Slider(minimum=0.5, maximum=2.0, value=1.0, step=0.1, label="سرعة الكلام")
],
outputs=[
gr.Textbox(label="رد ChatGPT"),
gr.Audio(type="filepath", label="الصوت الناتج")
],
title="مساعد ذكي باللهجة النجدية + تحويل النص لصوت",
description="اكتب أي نص، احصل على رد ذكي من GPT-4o وحوّله مباشرة لصوت باللهجة النجدية.",
flagging_mode="never"
)

iface.launch()
اريده على شكل موقع تفاعلي

Files changed (1) hide show
  1. README.md +8 -5
README.md CHANGED
@@ -1,10 +1,13 @@
1
  ---
2
- title: Deepsite Project
3
- emoji: 😻
4
- colorFrom: gray
5
- colorTo: indigo
6
  sdk: static
7
  pinned: false
 
 
8
  ---
9
 
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
1
  ---
2
+ title: DeepSite Project
3
+ colorFrom: pink
4
+ colorTo: gray
5
+ emoji: 🐳
6
  sdk: static
7
  pinned: false
8
+ tags:
9
+ - deepsite-v3
10
  ---
11
 
12
+ # Welcome to your new DeepSite project!
13
+ This project was created with [DeepSite](https://deepsite.hf.co).