testUni / app.py
belalmunsh's picture
Update app.py
978720b verified
raw
history blame
1.06 kB
import gradio as gr
from transformers import pipeline
import pdf2image
import pytesseract
# Initialize model
qa_model = pipeline("question-answering")
def process_pdf(pdf_file):
# Convert PDF to text
text = extract_text_from_pdf(pdf_file)
return text
def answer_question(question, context):
# Get answer from model
answer = qa_model(question=question, context=context)
return answer['answer']
# Create interface
with gr.Blocks() as demo:
gr.Markdown("# My Study Assistant")
# File upload
file_input = gr.File(label="Upload PDF")
# Text display
text_output = gr.Textbox(label="Extracted Text")
# Chat interface
question = gr.Textbox(label="Ask a question")
answer = gr.Textbox(label="Answer")
# Buttons
upload_btn = gr.Button("Process PDF")
ask_btn = gr.Button("Ask")
# Set up actions
upload_btn.click(process_pdf, inputs=file_input, outputs=text_output)
ask_btn.click(answer_question, inputs=[question, text_output], outputs=answer)
demo.launch()