|
import requests |
|
import gradio as gr |
|
import openai |
|
|
|
openai.api_key = "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" |
|
|
|
|
|
|
|
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"] |
|
}) |
|
|
|
|
|
def gpt(text): |
|
if not text: |
|
return "Veuillez saisir une question." |
|
f_prompt = f""" reformule ça |
|
{text}. """ |
|
|
|
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 |
|
|
|
iface = gr.Interface( |
|
fn=infer, |
|
title="Mariam - Beta", |
|
description=" La maj du siècle. ", |
|
inputs=[gr.Image(type="pil")], |
|
outputs=gr.Text(), |
|
).launch() |