alakxender commited on
Commit
b94b651
·
1 Parent(s): 6c65cf7
Files changed (2) hide show
  1. app.py +45 -6
  2. requirements.txt +1 -1
app.py CHANGED
@@ -4,10 +4,9 @@
4
  """
5
  import spaces
6
  import gradio as gr
7
- from deep_translator import GoogleTranslator
8
- from transformers import pipeline
9
-
10
- pipe = pipeline("summarization", model="facebook/bart-large-cnn")
11
 
12
  summary_type = {
13
  "short":{
@@ -119,5 +118,45 @@ iface = gr.Interface(
119
  ]
120
  )
121
 
122
- # Launch the Gradio interface
123
- iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  """
5
  import spaces
6
  import gradio as gr
7
+ import subprocess
8
+ import sys
9
+ import os
 
10
 
11
  summary_type = {
12
  "short":{
 
118
  ]
119
  )
120
 
121
+ def install_requirements():
122
+ requirements_path = 'requirements.txt'
123
+
124
+ # Check if requirements.txt exists
125
+ if not os.path.exists(requirements_path):
126
+ print("Error: requirements.txt not found")
127
+ return False
128
+
129
+ try:
130
+ print("Installing requirements...")
131
+ # Using --no-cache-dir to avoid memory issues
132
+ subprocess.check_call([
133
+ sys.executable,
134
+ "-m",
135
+ "pip",
136
+ "install",
137
+ "-r",
138
+ requirements_path,
139
+ "--no-cache-dir"
140
+ ])
141
+ print("Successfully installed all requirements")
142
+ return True
143
+ except subprocess.CalledProcessError as e:
144
+ print(f"Error installing requirements: {e}")
145
+ return False
146
+ except Exception as e:
147
+ print(f"Unexpected error: {e}")
148
+ return False
149
+
150
+ if __name__ == "__main__":
151
+ success = install_requirements()
152
+ if success:
153
+ print("All requirements installed successfully")
154
+ # Launch the Gradio interface
155
+ from deep_translator import GoogleTranslator
156
+ from transformers import pipeline
157
+
158
+ pipe = pipeline("summarization", model="facebook/bart-large-cnn")
159
+
160
+ iface.launch()
161
+ else:
162
+ print("Failed to install some requirements")
requirements.txt CHANGED
@@ -1,4 +1,4 @@
1
- deep-translator
2
  transformers
3
  tensorflow
4
  tf-keras
 
1
+ deep-translator==1.11.4
2
  transformers
3
  tensorflow
4
  tf-keras