ayajoharji commited on
Commit
8883dea
1 Parent(s): f5fc986

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -4
app.py CHANGED
@@ -1,5 +1,6 @@
1
  import gradio as gr
2
  import pandas as pd
 
3
 
4
  # Load recipes from CSV file
5
  def load_recipes(file_path):
@@ -28,14 +29,41 @@ def suggest_recipes(user_ingredients):
28
  return "لا توجد وصفات تتناسب مع المكونات المدخلة."
29
  return "\n\n".join(matching_recipes)
30
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  # Create the Gradio interface
32
  iface = gr.Interface(
33
- fn=suggest_recipes,
34
- inputs=gr.Textbox(label="ادخل المكونات (مفصولة بفواصل)"),
 
 
 
35
  outputs=gr.Textbox(label="الوصفات المقترحة"),
36
  title="اقتراحات الوصفات العربية",
37
- description="ادخل المكونات التي لديك للحصول على اقتراحات لوصفات عربية تقليدية."
38
  )
39
 
40
  if __name__ == "__main__":
41
- iface.launch()
 
1
  import gradio as gr
2
  import pandas as pd
3
+ import speech_recognition as sr
4
 
5
  # Load recipes from CSV file
6
  def load_recipes(file_path):
 
29
  return "لا توجد وصفات تتناسب مع المكونات المدخلة."
30
  return "\n\n".join(matching_recipes)
31
 
32
+ # Define the function to convert audio to text
33
+ def audio_to_text(audio_file):
34
+ recognizer = sr.Recognizer()
35
+ with sr.AudioFile(audio_file) as source:
36
+ audio_data = recognizer.record(source)
37
+ try:
38
+ text = recognizer.recognize_google(audio_data, language="ar")
39
+ return text
40
+ except sr.UnknownValueError:
41
+ return "لم أتمكن من فهم الصوت."
42
+ except sr.RequestError:
43
+ return "حدث خطأ في الاتصال بخدمة تحويل الصوت إلى نص."
44
+
45
+ def process_input(text_input, audio_file):
46
+ if audio_file:
47
+ user_ingredients = audio_to_text(audio_file)
48
+ else:
49
+ user_ingredients = text_input
50
+
51
+ if not user_ingredients:
52
+ return "يرجى إدخال المكونات."
53
+
54
+ return suggest_recipes(user_ingredients)
55
+
56
  # Create the Gradio interface
57
  iface = gr.Interface(
58
+ fn=process_input,
59
+ inputs=[
60
+ gr.Textbox(label="ادخل المكونات (مفصولة بفواصل)", placeholder="أدخل المكونات هنا", optional=True),
61
+ gr.Audio(source="microphone", type="filepath", label="تحدث لتحديد المكونات", optional=True)
62
+ ],
63
  outputs=gr.Textbox(label="الوصفات المقترحة"),
64
  title="اقتراحات الوصفات العربية",
65
+ description="ادخل المكونات التي لديك للحصول على اقتراحات لوصفات عربية تقليدية. يمكنك أيضاً التحدث لتحديد المكونات."
66
  )
67
 
68
  if __name__ == "__main__":
69
+ iface.launch()