asalhi85 commited on
Commit
35d6f49
1 Parent(s): be07a11

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -7
app.py CHANGED
@@ -35,6 +35,30 @@ DUPLICATE = """
35
 
36
  IMAGE_WIDTH = 512
37
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
  def extract_text_from(vid_link):
39
  video_url = vid_link
40
  yt = YouTube(video_url)
@@ -94,12 +118,13 @@ def bot(
94
  text_prompt = txt_in
95
 
96
  genai.configure(api_key=google_key)
 
97
  generation_config = genai.types.GenerationConfig(
98
- temperature=temperature,
99
- max_output_tokens=max_output_tokens,
100
  stop_sequences=preprocess_stop_sequences(stop_sequences=stop_sequences),
101
- top_k=top_k,
102
- top_p=top_p)
103
 
104
  if image_prompt is None:
105
  prompt= "استخرج كلمات مفتاحية من النص التالي: "+text_prompt
@@ -107,13 +132,13 @@ def bot(
107
  response = model.generate_content(
108
  prompt,
109
  stream=True,
110
- generation_config=generation_config)
111
  out1 = response.text
112
  prompt = "أذكر لي آية من القران الكريم تتحدث عن أحد هذه المواضيع او اكثر: "+ out1 + " واشرح الآيه وفسرها باللغة العربية."
113
  response = model.generate_content(
114
  prompt,
115
  stream=True,
116
- generation_config=generation_config)
117
  response.resolve()
118
  else:
119
  image_prompt = preprocess_image(image_prompt)
@@ -121,7 +146,7 @@ def bot(
121
  response = model.generate_content(
122
  contents=[text_prompt, image_prompt],
123
  stream=True,
124
- generation_config=generation_config)
125
  response.resolve()
126
 
127
  # streaming effect
 
35
 
36
  IMAGE_WIDTH = 512
37
 
38
+
39
+ afety_settings = [
40
+ {
41
+ "category": "HARM_CATEGORY_DANGEROUS",
42
+ "threshold": "BLOCK_NONE",
43
+ },
44
+ {
45
+ "category": "HARM_CATEGORY_HARASSMENT",
46
+ "threshold": "BLOCK_NONE",
47
+ },
48
+ {
49
+ "category": "HARM_CATEGORY_HATE_SPEECH",
50
+ "threshold": "BLOCK_NONE",
51
+ },
52
+ {
53
+ "category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
54
+ "threshold": "BLOCK_NONE",
55
+ },
56
+ {
57
+ "category": "HARM_CATEGORY_DANGEROUS_CONTENT",
58
+ "threshold": "BLOCK_NONE",
59
+ },]
60
+
61
+
62
  def extract_text_from(vid_link):
63
  video_url = vid_link
64
  yt = YouTube(video_url)
 
118
  text_prompt = txt_in
119
 
120
  genai.configure(api_key=google_key)
121
+
122
  generation_config = genai.types.GenerationConfig(
123
+ temperature=0.7,
124
+ max_output_tokens=2048
125
  stop_sequences=preprocess_stop_sequences(stop_sequences=stop_sequences),
126
+ top_k=40,
127
+ top_p=0.95)
128
 
129
  if image_prompt is None:
130
  prompt= "استخرج كلمات مفتاحية من النص التالي: "+text_prompt
 
132
  response = model.generate_content(
133
  prompt,
134
  stream=True,
135
+ generation_config=generation_config,afety_settings=afety_settings)
136
  out1 = response.text
137
  prompt = "أذكر لي آية من القران الكريم تتحدث عن أحد هذه المواضيع او اكثر: "+ out1 + " واشرح الآيه وفسرها باللغة العربية."
138
  response = model.generate_content(
139
  prompt,
140
  stream=True,
141
+ generation_config=generation_config, afety_settings=afety_settings)
142
  response.resolve()
143
  else:
144
  image_prompt = preprocess_image(image_prompt)
 
146
  response = model.generate_content(
147
  contents=[text_prompt, image_prompt],
148
  stream=True,
149
+ generation_config=generation_config, afety_settings=afety_settings)
150
  response.resolve()
151
 
152
  # streaming effect