asumait commited on
Commit
01c6915
·
verified ·
1 Parent(s): a59ca13

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -25
app.py CHANGED
@@ -1,40 +1,34 @@
1
  import os
2
  import gradio as gr
3
- from transformers import GPT2LMHeadModel, GPT2Tokenizer
4
- import torch
5
 
6
- # Clone the Gradio repository
7
- os.system("git clone https://github.com/gradio-app/gradio.git")
 
8
 
9
- # Install Gradio
10
- os.system("cd gradio && pip install .")
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 __init__(self):
20
- self.model_name = "EleutherAI/gpt-neo-2.7B"
21
- self.tokenizer = GPT2Tokenizer.from_pretrained(self.model_name)
22
- self.model = GPT2LMHeadModel.from_pretrained(self.model_name)
23
-
24
- def generate_response(self, input_text):
25
- input_ids = self.tokenizer.encode(input_text, return_tensors="pt")
26
- output = self.model.generate(input_ids, max_length=100, num_beams=5, no_repeat_ngram_size=2, top_k=50, top_p=0.95, temperature=0.7)
27
- response = self.tokenizer.decode(output[0], skip_special_tokens=True)
 
 
 
 
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)