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""" #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 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 #interface 1 app1 = gr.Interface(fn = infer,title="Mariam -Ocr ", inputs=[gr.Image(type="pil")], outputs=["text"]) #interface 2 app2 = gr.Interface(fn = gpt, inputs=gr.Textbox(label="Question:",lines=8), outputs=gr.Textbox()) demo = gr.TabbedInterface([app1, app2], ["OCR", "MARIAM-u"],description=description) demo.launch()