|
import gradio as gr |
|
import openai |
|
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""" |
|
|
|
description_ocr = """Quand tu finis d'importer le texte sélectionne le et copie le !!!!""" |
|
|
|
|
|
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 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
openai.api_key = "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" |
|
|
|
def gpt(prompt): |
|
if not prompt: |
|
return "Veuillez saisir une question." |
|
f_prompt = f""" |
|
{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 |
|
|
|
|
|
|
|
|
|
app1 = gr.Interface(fn = infer,title="Mariam -Ocr ",description=description_ocr, inputs=[gr.Image(type="pil")], outputs=["text"]) |
|
|
|
|
|
app2 = gr.Interface(fn = gpt,title="Mariam-U", description=description, inputs=gr.Textbox(label="Question:",lines=8), outputs=gr.Textbox()) |
|
|
|
demo = gr.TabbedInterface([app1, app2], ["OCR", "MARIAM-u"]) |
|
|
|
demo.launch() |