ayajoharji commited on
Commit
1669692
1 Parent(s): 765f23c

Update app.py

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