import torch import gradio as gr # Use a pipeline as a high-level helper from transformers import pipeline #modal_path = ("../Models/models--deepset--roberta-base-squad2/snapshots/cbf50ba81465d4d8676b8bab348e31835147541b") #question_answer = pipeline("question-answering", model=modal_path) question_answer = pipeline("question-answering", model="deepset/roberta-base-squad2") def read_file_content(file_path): try: with open(file_path, 'r') as file_obj: content = file_obj.read() if content is not None: return content except Exception as e: print(f"An error occurred while reading the file: {e}") return None def get_answer_from_context(file, question): context = read_file_content(file) get_answer = question_answer(question=question, context=context) return get_answer['answer'] gr.close_all() demo = gr.Interface(fn=get_answer_from_context, inputs= [gr.File(label='Upload Document File'), gr.Textbox(label='Ask Question', lines=1)], outputs= [gr.Textbox(label='Your Answer is', lines=1)], title= "Generative AI Project #3: Get Answer from the provide txt File", description="THIS APPLICATION WILL BE USED TO GET ANSWER FROM THE CONTEXT WHICH YOU WILL UPLOAD") demo.launch()