vizsum-pro / ui.py
Vartex39's picture
Özeti panoya kopyalama butonu eklendi
55f43e1
raw
history blame
2.44 kB
import gradio as gr
import tempfile # Bu satır eksikti
from ocr_engine import extract_text_from_image
from pdf_reader import extract_text_from_pdf
from summarizer import summarize_text
def process_input(pdf, image, manual_text, mode, model_name):
if pdf is not None:
text = extract_text_from_pdf(pdf)
elif image is not None:
text = extract_text_from_image(image)
elif manual_text.strip() != "":
text = manual_text
else:
return "Lütfen bir giriş türü seçin.", "", None
if "[ERROR]" in text:
return text, "", None
summary = summarize_text(text, mode, model_name)
temp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".txt", mode='w', encoding='utf-8')
temp_file.write(summary)
temp_file.close()
return text, summary, temp_file.name
with gr.Blocks() as demo:
gr.Markdown("## VizSum")
with gr.Row():
pdf_input = gr.File(label="PDF Yükle", file_types=[".pdf"])
image_input = gr.Image(type="filepath", label="Görsel Yükle")
manual_input = gr.Textbox(lines=5, label="Metni Manuel Gir")
mode_selector = gr.Dropdown(
choices=["Teknik Özet", "Sade Anlatım", "Eleştir ve Değerlendir", "Başlık Çıkar", "Not Formatı"],
label="Özetleme Modu",
value="Teknik Özet"
)
model_selector = gr.Dropdown(
choices=[
"anthropic/claude-3-haiku",
"openai/gpt-3.5-turbo",
"mistralai/mistral-7b-instruct"
],
label="Dil Modeli",
value="anthropic/claude-3-haiku"
)
with gr.Row():
submit_btn = gr.Button("Özetle")
with gr.Row():
text_output = gr.Textbox(label="Giriş Metni")
copy_btn = gr.Button("Özeti Kopyala")
copy_status = gr.Textbox(visible=False)
summary_output = gr.Textbox(label="AI Özeti")
summary_file = gr.File(label="Özeti İndir", interactive=True)
submit_btn.click(
fn=process_input,
inputs=[pdf_input, image_input, manual_text, mode_selector, model_selector],
outputs=[text_output, summary_output, summary_file]
)
copy_btn.click(
fn=lambda summary: (summary, "✔️ Özet panoya kopyalandı."),
inputs=[summary_output],
outputs=[summary_output, copy_status],
js="navigator.clipboard.writeText(arguments[0]);"
)
if __name__ == "__main__":
demo.launch(share=True)