Update app.py
Browse files
app.py
CHANGED
@@ -1,40 +1,34 @@
|
|
1 |
import os
|
2 |
import gradio as gr
|
3 |
-
|
4 |
-
import torch
|
5 |
|
6 |
-
#
|
7 |
-
os.system("
|
|
|
8 |
|
9 |
-
#
|
10 |
-
|
11 |
-
|
12 |
-
# Install transformers
|
13 |
-
os.system("pip install transformers")
|
14 |
-
|
15 |
-
# Install PyTorch
|
16 |
-
os.system("pip install torch==1.10.0+cpu torchvision==0.11.1+cpu torchaudio==0.10.0+cpu -f https://download.pytorch.org/whl/cpu/torch_stable.html")
|
17 |
|
18 |
class ArabicAssistant:
|
19 |
-
def
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
|
|
|
|
|
|
|
|
28 |
return response
|
29 |
|
30 |
assistant = ArabicAssistant()
|
31 |
|
32 |
def chatbot_interaction(user_input):
|
33 |
user_input = user_input.strip()
|
34 |
-
|
35 |
-
# Check if the user input is in Arabic-Egyptian dialect
|
36 |
-
if not any(char in "اأإآبتثجحخدذرزسشصضطظعغفقكلمنهوي" for char in user_input):
|
37 |
-
return "عذرًا، أنا أتحدث فقط باللهجة المصرية. يرجى استخدام اللهجة المصرية في التفاعل معي."
|
38 |
|
39 |
# Generate response using the chatbot model
|
40 |
response = assistant.generate_response(user_input)
|
|
|
1 |
import os
|
2 |
import gradio as gr
|
3 |
+
import openai
|
|
|
4 |
|
5 |
+
# Install required libraries
|
6 |
+
os.system("pip install gradio")
|
7 |
+
os.system("pip install openai")
|
8 |
|
9 |
+
# Set your OpenAI API key
|
10 |
+
openai.api_key = "your_api_key_here" # Replace with your actual API key
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
class ArabicAssistant:
|
13 |
+
def generate_response(self, user_input):
|
14 |
+
# Check if the user input is in Arabic-Egyptian dialect
|
15 |
+
if not any(char in "اأإآبتثجحخدذرزسشصضطظعغفقكلمنهوي" for char in user_input):
|
16 |
+
return "عذرًا، أنا أتحدث فقط باللهجة المصرية. يرجى استخدام اللهجة المصرية في التفاعل معي."
|
17 |
+
|
18 |
+
# Generate response using the ChatGPT 3.5 model
|
19 |
+
response = openai.Completion.create(
|
20 |
+
model="text-davinci-003",
|
21 |
+
prompt=user_input,
|
22 |
+
temperature=0.7,
|
23 |
+
max_tokens=100
|
24 |
+
)["choices"][0]["text"].strip()
|
25 |
+
|
26 |
return response
|
27 |
|
28 |
assistant = ArabicAssistant()
|
29 |
|
30 |
def chatbot_interaction(user_input):
|
31 |
user_input = user_input.strip()
|
|
|
|
|
|
|
|
|
32 |
|
33 |
# Generate response using the chatbot model
|
34 |
response = assistant.generate_response(user_input)
|