Mohamed2002 commited on
Commit
8e99fee
1 Parent(s): 4e35413

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -29
app.py CHANGED
@@ -1,36 +1,31 @@
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()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import pipeline
3
 
4
+ # Load the translation models and the custom chatbot model
 
 
 
 
5
  translator_ar_en = pipeline('translation_ar_to_en', model='Helsinki-NLP/opus-mt-ar-en')
6
  translator_en_ar = pipeline('translation_en_to_ar', model='Helsinki-NLP/opus-mt-en-ar')
7
+ custom_model = pipeline('text2text-generation', model='Mohamed2002/product_model')
 
8
 
9
  def translate(text, translator):
10
  return translator(text)[0]['translation_text']
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
+ # Streamlit app
13
+ st.title("Arabic Chatbot")
14
+
15
+ st.write("(:اهلا بحضرتك في تطبيق السمسار الالكتروني")
16
+
17
+ user_input = st.text_input("العميل:")
18
+
19
+ if st.button("Submit"):
20
+ try:
21
+ # Translate user input from Arabic to English
22
+ translated_input = translate(user_input, translator_ar_en)
23
+
24
+ # Generate prediction
25
+ prediction = custom_model(translated_input)[0]['generated_text']
26
+
27
+ # Translate response from English to Arabic
28
+ translated_response = translate(prediction, translator_en_ar)
29
+ st.write("السمسار:", translated_response)
30
+ except Exception as e:
31
+ st.write(f"An error occurred: {str(e)}")