Spaces:
Runtime error
Runtime error
Update app.py
Browse files1234567891011121314151617181920212223242526272829303132333435363738394041import torchimport gradio as gr# Use a pipeline as a high-level helperfrom 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 contentexcept Exception as e:print(f"An error occurred while reading the file: {e}")return Nonedef 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()
app.py+41