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