Spaces:
Runtime error
Runtime error
Mohamed2002
commited on
Commit
•
010583e
1
Parent(s):
1b09332
Update app.py
Browse files
app.py
CHANGED
@@ -1,42 +1,37 @@
|
|
1 |
-
from
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
model = AutoModelForSeq2SeqLM.from_pretrained('product_model')
|
6 |
-
|
7 |
-
# Load the translation models
|
8 |
-
translator_ar_en = pipeline('translation_ar_to_en', model='Helsinki-NLP/opus-mt-ar-en')
|
9 |
-
translator_en_ar = pipeline('translation_en_to_ar', model='Helsinki-NLP/opus-mt-en-ar')
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
except Exception as e:
|
39 |
-
return jsonify({'error': str(e)}), 500
|
40 |
-
|
41 |
-
if __name__ == '__main__':
|
42 |
-
app.run(host='0.0.0.0', port=5000)
|
|
|
1 |
+
from transformers import AutoModelForSeq2SeqLM, pipeline
|
2 |
+
|
3 |
+
# Load the previously trained and saved model
|
4 |
+
model_path = r'C:\Users\muham\OneDrive\Desktop\certificates\product_model'
|
5 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(r'C:\Users\muham\OneDrive\Desktop\certificates\product_model')
|
6 |
+
|
7 |
+
# Load the translation models
|
8 |
+
translator_ar_en = pipeline('translation_ar_to_en', model='Helsinki-NLP/opus-mt-ar-en')
|
9 |
+
translator_en_ar = pipeline('translation_en_to_ar', model='Helsinki-NLP/opus-mt-en-ar')
|
10 |
+
# Create the custom model pipeline
|
11 |
+
custom_model = pipeline('text2text-generation', model=r'C:\Users\muham\OneDrive\Desktop\certificates\product_model')
|
12 |
+
|
13 |
+
def translate(text, translator):
|
14 |
+
return translator(text)[0]['translation_text']
|
15 |
+
def chat_with_bot():
|
16 |
+
print("(:اهلا بحضرتك في تطبيق السمسار الالكتروني")
|
17 |
+
while True:
|
18 |
+
# Get user input
|
19 |
+
user_input = input("العميل: ")
|
20 |
+
if user_input.lower() == 'quit':
|
21 |
+
break
|
22 |
+
|
23 |
+
# Translate user input from Arabic to English
|
24 |
+
try:
|
25 |
+
translated_input = translate(user_input, translator_ar_en)
|
26 |
+
|
27 |
+
# Generate prediction
|
28 |
+
prediction = custom_model(translated_input)[0]['generated_text']
|
29 |
+
# Translate response from English to Arabic
|
30 |
+
translated_response = translate(prediction, translator_en_ar)
|
31 |
+
print("السمسار:", translated_response)
|
32 |
+
except Exception as e:
|
33 |
+
print(f"An error occurred: {str(e)}")
|
34 |
+
|
35 |
+
# Start chatting with the bot
|
36 |
+
chat_with_bot()
|
37 |
+
|
|
|
|
|
|
|
|
|
|