|
import os |
|
import gradio as gr |
|
import openai |
|
|
|
|
|
os.system("pip install gradio") |
|
os.system("pip install openai") |
|
|
|
|
|
openai.api_key = "your_api_key_here" |
|
|
|
class ArabicAssistant: |
|
def generate_response(self, user_input): |
|
|
|
if not any(char in "اأإآبتثجحخدذرزسشصضطظعغفقكلمنهوي" for char in user_input): |
|
return "عذرًا، أنا أتحدث فقط باللهجة المصرية. يرجى استخدام اللهجة المصرية في التفاعل معي." |
|
|
|
|
|
response = openai.Completion.create( |
|
model="text-davinci-003", |
|
prompt=user_input, |
|
temperature=0.7, |
|
max_tokens=100 |
|
)["choices"][0]["text"].strip() |
|
|
|
return response |
|
|
|
assistant = ArabicAssistant() |
|
|
|
def chatbot_interaction(user_input): |
|
user_input = user_input.strip() |
|
|
|
|
|
response = assistant.generate_response(user_input) |
|
|
|
|
|
response += " أهلاً! كيف يمكنني مساعدتك اليوم؟" |
|
|
|
return response |
|
|
|
iface = gr.Interface(fn=chatbot_interaction, inputs=gr.Textbox(), outputs=gr.Textbox(), live=True, theme="huggingface", layout="vertical", title="Arabic Assistant Chatbot", description="Chat with the Arabic Assistant in the Egyptian dialect.") |
|
iface.launch() |
|
|