Spaces:
Runtime error
Runtime error
Update main.py
Browse files
main.py
CHANGED
|
@@ -157,12 +157,14 @@ app = Flask(__name__)
|
|
| 157 |
# Data ingestion
|
| 158 |
data_ingestion_from_directory()
|
| 159 |
|
| 160 |
-
# Generate Response
|
| 161 |
-
def generate_response(query,language):
|
| 162 |
try:
|
| 163 |
# Call the handle_query function to get the response
|
| 164 |
bot_response = handle_query(query)
|
| 165 |
-
|
|
|
|
|
|
|
| 166 |
"hindi": "hi",
|
| 167 |
"bengali": "bn",
|
| 168 |
"telugu": "te",
|
|
@@ -175,20 +177,52 @@ def generate_response(query,language):
|
|
| 175 |
"odia": "or",
|
| 176 |
"urdu": "ur",
|
| 177 |
"assamese": "as",
|
| 178 |
-
"sanskrit": "sa"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 179 |
}
|
|
|
|
|
|
|
| 180 |
translated_text = bot_response
|
|
|
|
|
|
|
| 181 |
try:
|
| 182 |
-
|
| 183 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 184 |
except Exception as e:
|
| 185 |
# Handle translation errors
|
| 186 |
print(f"Translation error: {e}")
|
| 187 |
-
|
| 188 |
-
|
|
|
|
|
|
|
| 189 |
return translated_text
|
| 190 |
except Exception as e:
|
| 191 |
-
return f"Error fetching the response: {str(e)}"
|
| 192 |
|
| 193 |
# Route for the homepage
|
| 194 |
@app.route('/')
|
|
|
|
| 157 |
# Data ingestion
|
| 158 |
data_ingestion_from_directory()
|
| 159 |
|
| 160 |
+
# Generate Response
|
| 161 |
+
def generate_response(query, language):
|
| 162 |
try:
|
| 163 |
# Call the handle_query function to get the response
|
| 164 |
bot_response = handle_query(query)
|
| 165 |
+
|
| 166 |
+
# Map of supported languages
|
| 167 |
+
supported_languages = {
|
| 168 |
"hindi": "hi",
|
| 169 |
"bengali": "bn",
|
| 170 |
"telugu": "te",
|
|
|
|
| 177 |
"odia": "or",
|
| 178 |
"urdu": "ur",
|
| 179 |
"assamese": "as",
|
| 180 |
+
"sanskrit": "sa",
|
| 181 |
+
"arabic": "ar",
|
| 182 |
+
"australian": "en-AU",
|
| 183 |
+
"bangla-india": "bn-IN",
|
| 184 |
+
"chinese": "zh-CN",
|
| 185 |
+
"dutch": "nl",
|
| 186 |
+
"french": "fr",
|
| 187 |
+
"filipino": "tl",
|
| 188 |
+
"greek": "el",
|
| 189 |
+
"indonesian": "id",
|
| 190 |
+
"italian": "it",
|
| 191 |
+
"japanese": "ja",
|
| 192 |
+
"korean": "ko",
|
| 193 |
+
"latin": "la",
|
| 194 |
+
"nepali": "ne",
|
| 195 |
+
"portuguese": "pt",
|
| 196 |
+
"romanian": "ro",
|
| 197 |
+
"russian": "ru",
|
| 198 |
+
"spanish": "es",
|
| 199 |
+
"swedish": "sv",
|
| 200 |
+
"thai": "th",
|
| 201 |
+
"ukrainian": "uk",
|
| 202 |
+
"turkish": "tr"
|
| 203 |
}
|
| 204 |
+
|
| 205 |
+
# Initialize the translated text
|
| 206 |
translated_text = bot_response
|
| 207 |
+
|
| 208 |
+
# Translate only if the language is supported and not English
|
| 209 |
try:
|
| 210 |
+
if language in supported_languages:
|
| 211 |
+
target_lang = supported_languages[language]
|
| 212 |
+
translated_text = GoogleTranslator(source='en', target=target_lang).translate(bot_response)
|
| 213 |
+
print(translated_text)
|
| 214 |
+
else:
|
| 215 |
+
print(f"Unsupported language: {language}")
|
| 216 |
except Exception as e:
|
| 217 |
# Handle translation errors
|
| 218 |
print(f"Translation error: {e}")
|
| 219 |
+
translated_text = "Sorry, I couldn't translate the response."
|
| 220 |
+
|
| 221 |
+
# Append to chat history
|
| 222 |
+
chat_history.append((query, translated_text))
|
| 223 |
return translated_text
|
| 224 |
except Exception as e:
|
| 225 |
+
return f"Error fetching the response: {str(e)}"
|
| 226 |
|
| 227 |
# Route for the homepage
|
| 228 |
@app.route('/')
|