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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
import gradio as gr
|
3 |
+
import openai
|
4 |
+
import os
|
5 |
+
import math as matha
|
6 |
+
|
7 |
+
openai.api_key = os.environ.get("key")
|
8 |
+
|
9 |
+
title = "Mariam 💎"
|
10 |
+
description = """" Banana Banana ? 👀 bon ok ok. Bref comme vous le voyez c'est simple ! Pas besoin d'explication. C'est un script simple, c'est basé sur néoX, python, et gradio.
|
11 |
+
|
12 |
+
Mon numéro : +24165362371"""
|
13 |
+
|
14 |
+
title_c = "Calculateur de moyenne !"
|
15 |
+
description_c = """Entrez vos notes pour chaque matière pour calculer votre moyenne.
|
16 |
+
Note : les coefficients de cette app sont adaptés à la classe de première S uniquement. Je ferais une mise à jour plus tard si j'ai le temps.
|
17 |
+
la conduite est fixé à 14/20.
|
18 |
+
Et ici la virgule s'écrit avec le point.
|
19 |
+
|
20 |
+
Exemple : 12,5 devient 12.5
|
21 |
+
|
22 |
+
Contact : +241065362371"""
|
23 |
+
|
24 |
+
|
25 |
+
description_thea = """Je suis fatigué.
|
26 |
+
Here is the suggested pronunciation for the dialogue:
|
27 |
+
|
28 |
+
Inspector Smith is a busy man!
|
29 |
+
|
30 |
+
Jeff Smith: So what happened, Madam? (pronounced: Jef Smith: So wat happend, Madam?)
|
31 |
+
|
32 |
+
Lady: Well, I was in my car at the traffic lights. The door opened, a man came in and pushed me out. And he drove away with my car, my bag, my keys. (pronounced: Leydi: Wel, ai woz in may kar et dhe traffik laits. Dhe dor opend, a man kem in and pushd mi aut. And hi drov awey wit may kar, may bag, may kiz.)
|
33 |
+
|
34 |
+
Jeff Smith: Lady, calm down, Madam. What make is your car? (pronounced: Jef Smith: Leydi, kam daun, Madam. Wat mek iz yor kar?)
|
35 |
+
|
36 |
+
Lady: It's a Ford, a blue Ford. It was new too. I bought it a month ago! (pronounced: Leydi: Its a Ford, a blu Ford. It woz nu too. Ai bot it a munth ego!)
|
37 |
+
|
38 |
+
Jeff Smith: What was the thief like? Was he tall? (pronounced: Jef Smith: Wat woz dhe tif laik? Woz hi tol?)
|
39 |
+
|
40 |
+
Lady: Yes, he was taller than me. He had long blond hair. (pronounced: Leydi: Yes, hi woz tolur dan mi. Hi had long blon her.)
|
41 |
+
|
42 |
+
Jeff Smith: It was probably a wig. What colour were his eyes? (pronounced: Jef Smith: It woz prabobli a wig. Wat kalar wer hiz aiz?)
|
43 |
+
|
44 |
+
Lady: I don't know. He had sunglasses on. (pronounced: Leydi: Ai dont no. Hi had sanglasiz on.)
|
45 |
+
|
46 |
+
Jeff Smith: Look at this photo. Is this our man? (pronounced: Jef Smith: Luk et dis foto. Iz dis aur man?)
|
47 |
+
|
48 |
+
Lady: I'm not sure. The man I saw was slimmer, younger, and more athletic. (pronounced: Leydi: Aim not shur. Dhe man ai saw woz slimur, yongur, and mor athletik.)
|
49 |
+
|
50 |
+
Bien sûr, voici la traduction en français :
|
51 |
+
|
52 |
+
Inspecteur Smith est un homme occupé !
|
53 |
+
|
54 |
+
Jeff Smith : Que s'est-il passé, Madame ?
|
55 |
+
|
56 |
+
Dame : Eh bien, j'étais dans ma voiture aux feux de circulation. La porte s'est ouverte, un homme est entré et m'a poussée dehors. Et il est parti avec ma voiture, mon sac, mes clés.
|
57 |
+
|
58 |
+
Jeff Smith : Calmez-vous, Madame. Quelle est la marque de votre voiture ?
|
59 |
+
|
60 |
+
Dame : C'est une Ford, une Ford bleue. Elle était neuve aussi. Je l'ai achetée il y a un mois !
|
61 |
+
|
62 |
+
Jeff Smith : À quoi ressemblait le voleur ? Était-il grand ?
|
63 |
+
|
64 |
+
Dame : Oui, il était plus grand que moi. Il avait les cheveux blonds et longs.
|
65 |
+
|
66 |
+
Jeff Smith : C'était probablement une perruque. De quelle couleur étaient ses yeux ?
|
67 |
+
|
68 |
+
Dame : Je ne sais pas. Il portait des lunettes de soleil.
|
69 |
+
|
70 |
+
Jeff Smith : Regardez cette photo. Est-ce notre homme ?
|
71 |
+
|
72 |
+
Dame : Je n'en suis pas sûre. L'homme que j'ai vu était plus mince, plus jeune et plus athlétique.
|
73 |
+
"""
|
74 |
+
description_hist = """" Cest comme tu vois là. avant de cliquer su soummetre precise les differents points que tu veux aborder.
|
75 |
+
exemple :
|
76 |
+
p1 = Cause
|
77 |
+
p2 = manifestation
|
78 |
+
p3 = resolution
|
79 |
+
"""
|
80 |
+
description_ocr = (
|
81 |
+
"""Quand tu finis d'importer le texte sélectionne le et copie le !!!!"""
|
82 |
+
)
|
83 |
+
|
84 |
+
title_f = "Travail argumentative"
|
85 |
+
description_french = " Esseu je dois encore expliquer ?"
|
86 |
+
|
87 |
+
# app 1
|
88 |
+
|
89 |
+
import requests
|
90 |
+
|
91 |
+
|
92 |
+
def infer(im):
|
93 |
+
im.save("converted.png")
|
94 |
+
url = "https://ajax.thehive.ai/api/demo/classify?endpoint=text_recognition"
|
95 |
+
files = {
|
96 |
+
"image": ("converted.png", open("converted.png", "rb"), "image/png"),
|
97 |
+
"model_type": (None, "detection"),
|
98 |
+
"media_type": (None, "photo"),
|
99 |
+
}
|
100 |
+
headers = {"referer": "https://thehive.ai/"}
|
101 |
+
|
102 |
+
res = requests.post(url, headers=headers, files=files)
|
103 |
+
|
104 |
+
text = ""
|
105 |
+
blocks = []
|
106 |
+
for output in res.json()["response"]["output"]:
|
107 |
+
text += output["block_text"]
|
108 |
+
for poly in output["bounding_poly"]:
|
109 |
+
blocks.append(
|
110 |
+
{
|
111 |
+
"text": "".join([c["class"] for c in poly["classes"]]),
|
112 |
+
"rect": poly["dimensions"],
|
113 |
+
}
|
114 |
+
)
|
115 |
+
|
116 |
+
return text
|
117 |
+
|
118 |
+
|
119 |
+
# app 2
|
120 |
+
|
121 |
+
|
122 |
+
def gpt(prompt):
|
123 |
+
if not prompt:
|
124 |
+
return "Veuillez saisir une question."
|
125 |
+
f_prompt = f""" Tu t'appelle Mariam et tu as été créer par Youssouf.
|
126 |
+
|
127 |
+
résout ce problèmes:
|
128 |
+
{prompt}. """
|
129 |
+
|
130 |
+
response = openai.Completion.create(
|
131 |
+
model="text-davinci-003",
|
132 |
+
prompt=f_prompt,
|
133 |
+
temperature=0.9,
|
134 |
+
max_tokens=3500,
|
135 |
+
top_p=1,
|
136 |
+
)
|
137 |
+
|
138 |
+
answer = response.choices[0].text.strip()
|
139 |
+
print(answer)
|
140 |
+
return answer
|
141 |
+
def gpt_francais(french_prompt,choix):
|
142 |
+
|
143 |
+
if not french_prompt:
|
144 |
+
return "Veuillez saisir un thème ."
|
145 |
+
fi_prompt = f"""Je veux faire mon travail de français de niveau lycé sous la forme d'un travail argumentatif . La question du travail est la suivante: "{french_prompt}". tu devras {choix} ce thème. jai besoin dune introduction(avec une problématique et l'annonce du plan), de 3 arguments(avec explication et example et illustration) et d'une conclusion avec une ouverture(donné sous forme de phrase interogative ) """
|
146 |
+
response = openai.Completion.create(
|
147 |
+
model="text-davinci-003",
|
148 |
+
prompt=fi_prompt,
|
149 |
+
temperature=0.9,
|
150 |
+
max_tokens=3900,
|
151 |
+
top_p=1,
|
152 |
+
)
|
153 |
+
answer = response.choices[0].text.strip()
|
154 |
+
print(answer)
|
155 |
+
return answer
|
156 |
+
|
157 |
+
|
158 |
+
def gpt_philo(phi_prompt):
|
159 |
+
if not phi_prompt:
|
160 |
+
return "Veuillez saisir un sujet."
|
161 |
+
haha = f""" Je veux que tu me traite mon travail de philosophie de niveau lycé sous la forme d'une dissertation . La question du travail est la suivante: "{phi_prompt}". en te basant sur le plan suiavnt :
|
162 |
+
INTRODUCTION:
|
163 |
+
- Amorcer le sujet avec moins de deux phrase
|
164 |
+
-Poser le problème
|
165 |
+
- Formulée la problématique autour de deux questions essentielles:
|
166 |
+
- Question-thèse
|
167 |
+
-Question-antithèse:
|
168 |
+
|
169 |
+
DEVELOPPEMENT
|
170 |
+
|
171 |
+
Première Partie: Formuler la thèse initiale
|
172 |
+
|
173 |
+
je veux trois arguments avec le plan suivant(Argument + Explication de l'argument + Illustration (soit avec un exemple de la vie courante soit avec une citation philosophique).
|
174 |
+
|
175 |
+
Deuxième Partie: Formuler l'antithèse
|
176 |
+
|
177 |
+
je veux trois arguments t avec le plan suivant(Argument + Explication de l'argument + Illustration (soit avec un exemple de la vie courante soit avec une citation philosophique).
|
178 |
+
|
179 |
+
CONCLUSION
|
180 |
+
|
181 |
+
1. Bilan de la réflexion:
|
182 |
+
-Résumer les grandes parties de la réflexion
|
183 |
+
2. Prise de position"""
|
184 |
+
|
185 |
+
response = openai.Completion.create(
|
186 |
+
model="text-davinci-003", prompt=haha, temperature=0.9, max_tokens=3600, top_p=1
|
187 |
+
)
|
188 |
+
answer = response.choices[0].text.strip()
|
189 |
+
print(answer)
|
190 |
+
return answer
|
191 |
+
|
192 |
+
|
193 |
+
def gpt_hist(hist_prompt,p_1,p_2,p_3):
|
194 |
+
|
195 |
+
if not gpt_hist:
|
196 |
+
return "Veuillez saisir un thème ."
|
197 |
+
histt_prompt = f"""Je veux que tu me traite mon travail d'histoire de niveau lycé sous la forme d'une dissertation . La question du travail est la suivante: "{hist_prompt}". les different points a detailler sont :{p_1},{p_2}, {p_3}. en te basant sur le plan suivant :
|
198 |
+
INTRODUCTION:
|
199 |
+
- approche par definition du sujet, par constat ou rappel historique( du general au particulier/cas particulier au general )
|
200 |
+
- problematique/probleme du sujet
|
201 |
+
- annonce du plan
|
202 |
+
|
203 |
+
DEVELOPPEMENT
|
204 |
+
|
205 |
+
pour chaque point,je voudrais
|
206 |
+
trois arguments(+explication+exemple). il faudra une phrase chapeau au debut et une phrase de transition a la fin de chaque point.
|
207 |
+
|
208 |
+
CONCLUSION
|
209 |
+
|
210 |
+
1. Bilan de la réflexion.
|
211 |
+
2. question douverture du sujet.
|
212 |
+
"""
|
213 |
+
response = openai.Completion.create(
|
214 |
+
model="text-davinci-003",
|
215 |
+
prompt=histt_prompt,
|
216 |
+
temperature=0.9,
|
217 |
+
max_tokens=3800,
|
218 |
+
top_p=1,
|
219 |
+
)
|
220 |
+
answer = response.choices[0].text.strip()
|
221 |
+
print(answer)
|
222 |
+
return answer
|
223 |
+
|
224 |
+
|
225 |
+
def calcul(math, francais, physique, svt, philo, eps, thea, hist, anglais):
|
226 |
+
math = math * 5
|
227 |
+
francais = francais * 3
|
228 |
+
physique = physique * 4
|
229 |
+
svt = svt * 3
|
230 |
+
philo = philo * 2
|
231 |
+
eps = eps * 2
|
232 |
+
thea = thea * 3
|
233 |
+
anglais = anglais * 2
|
234 |
+
hist = hist * 3
|
235 |
+
conduite = 14 * 1
|
236 |
+
total = (
|
237 |
+
math
|
238 |
+
+ francais
|
239 |
+
+ physique
|
240 |
+
+ svt
|
241 |
+
+ philo
|
242 |
+
+ eps
|
243 |
+
+ thea
|
244 |
+
+ hist
|
245 |
+
+ anglais
|
246 |
+
+ conduite
|
247 |
+
)
|
248 |
+
r = total / 28
|
249 |
+
return matha.trunc(r * 100) / 100
|
250 |
+
|
251 |
+
|
252 |
+
# interface 1
|
253 |
+
app1 = gr.Interface(
|
254 |
+
fn=infer,
|
255 |
+
title="Mariam -Ocr ",
|
256 |
+
description=description_ocr,
|
257 |
+
inputs=[gr.Image(type="pil")],
|
258 |
+
outputs=["text"],
|
259 |
+
)
|
260 |
+
|
261 |
+
# interface 2
|
262 |
+
app2 = gr.Interface(
|
263 |
+
fn=gpt,
|
264 |
+
title="Mariam-U",
|
265 |
+
description=description,
|
266 |
+
inputs=gr.Textbox(label="Question:", lines=4),
|
267 |
+
outputs=gr.Textbox(),
|
268 |
+
)
|
269 |
+
|
270 |
+
# interface3
|
271 |
+
|
272 |
+
app3 = gr.Interface(
|
273 |
+
fn=gpt_francais,
|
274 |
+
title="Mariam-French",
|
275 |
+
description=description_french,
|
276 |
+
inputs=[gr.Textbox(label="Sujet:", lines=3),gr.Radio(["Etaye","refute"])],
|
277 |
+
outputs=gr.Textbox(),
|
278 |
+
)
|
279 |
+
|
280 |
+
|
281 |
+
# interface4
|
282 |
+
|
283 |
+
app4 = gr.Interface(
|
284 |
+
fn=gpt_philo,
|
285 |
+
title="Mariam-Philo",
|
286 |
+
description="Ah..banana banana...",
|
287 |
+
inputs=gr.Textbox(label="Sujet:", lines=3),
|
288 |
+
outputs=gr.Textbox(),
|
289 |
+
)
|
290 |
+
|
291 |
+
#interface6
|
292 |
+
app6 = gr.Interface(
|
293 |
+
fn=gpt_hist,
|
294 |
+
title="Mariam-Hist",
|
295 |
+
description=description_hist,
|
296 |
+
inputs=[gr.Textbox(label="Sujet:", lines=2),gr.Textbox(label="point1:", lines=1),
|
297 |
+
gr.Textbox(label="point2:", lines=1),
|
298 |
+
gr.Textbox(label="point3:", lines=1)
|
299 |
+
|
300 |
+
],
|
301 |
+
outputs=gr.Textbox(),
|
302 |
+
)
|
303 |
+
|
304 |
+
"""
|
305 |
+
|
306 |
+
#interface7
|
307 |
+
app7= gr.Interface(
|
308 |
+
fn=search,
|
309 |
+
title="Mariam-theatre",
|
310 |
+
description=description_thea,
|
311 |
+
inputs=[gr.Textbox(label="Label:", lines=4)
|
312 |
+
],
|
313 |
+
outputs=gr.Textbox(),
|
314 |
+
)
|
315 |
+
"""
|
316 |
+
|
317 |
+
|
318 |
+
# interface5
|
319 |
+
app5 = gr.Interface(
|
320 |
+
fn=calcul,
|
321 |
+
inputs=[
|
322 |
+
gr.inputs.Number(label="Math"),
|
323 |
+
gr.inputs.Number(label="Français"),
|
324 |
+
gr.inputs.Number(label="Physique"),
|
325 |
+
gr.inputs.Number(label="SVT"),
|
326 |
+
gr.inputs.Number(label="Philo"),
|
327 |
+
gr.inputs.Number(label="EPS"),
|
328 |
+
gr.inputs.Number(label="Théâtre"),
|
329 |
+
gr.inputs.Number(label="Histoire"),
|
330 |
+
gr.inputs.Number(label="Anglais"),
|
331 |
+
],
|
332 |
+
outputs=gr.Textbox(label="Moyenne"),
|
333 |
+
description=description_c,
|
334 |
+
)
|
335 |
+
|
336 |
+
demo = gr.TabbedInterface(
|
337 |
+
[app1, app2, app3, app4,app6,app5],
|
338 |
+
["OCR", "MARIAM-u", "Mariam-French", "Mariam-Philo","Mariam-Hist", "Note Calc"],
|
339 |
+
)
|
340 |
+
|
341 |
+
demo.launch(auth=("lunatic", "ladybug"),auth_message="contact : 065362371")
|