Spaces:
Runtime error
Runtime error
File size: 1,356 Bytes
e01d937 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | 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() |