Spaces:
Sleeping
Sleeping
Download app.py from AIROBOHUB/document-QnA: direct link, hf CLI and curl.
- Browser
- Download file 3.17 kB
-
https://huggingface.co/spaces/AIROBOHUB/document-QnA/resolve/main/app.py
- Command line
-
hf download hf://spaces/AIROBOHUB/document-QnA/app.py
-
curl -L -o app.py https://huggingface.co/spaces/AIROBOHUB/document-QnA/resolve/main/app.py
3.17 kB
| import torch | |
| import gradio as gr | |
| # Use a pipeline as a high-level helper | |
| from transformers import pipeline | |
| model_path=("../Models/models--deepset--roberta-base-squad2/snapshots" | |
| "/cbf50ba81465d4d8676b8bab348e31835147541b") | |
| question_answer = pipeline("question-answering", model="deepset/roberta-base-squad2") | |
| #question_answer = pipeline("question-answering", model=model_path) | |
| def load_text_from_file(file): | |
| """ | |
| Load and return the content of a text file from a file object. | |
| Parameters: | |
| file (file object): The file object representing the text file. | |
| Returns: | |
| str: The content of the text file. | |
| """ | |
| try: | |
| with open(file.name, 'r',encoding='utf-8') as file1: | |
| content = file1.read() | |
| return content | |
| except Exception as e: | |
| return f"Error reading from the provided file object: {e}" | |
| # # Example usage: | |
| # with open('example.txt', 'r', encoding='utf-8') as file: | |
| # content = load_text_from_file(file) | |
| # if content: | |
| # print("Content of the file:") | |
| # print(content) | |
| # else: | |
| # print("Failed to load the content of the file.") | |
| #development | |
| # context="Nara Chandrababu Naidu (born 20 April 1950), also known as Chandrababu Naidu or CBN, is an Indian politician and the current leader of the opposition in the Andhra Pradesh Legislative Assembly. He also served as Chief Minister from 1995 to 2004 and as opposition leader from 2004 to 2014 of Andhra Pradesh. He has been the president of the Telugu Desam Party (TDP) since 1995.[2]Naidu's political career began in the 1970s with the Indian National Congress (INC). In 1978, he was elected to the Andhra Pradesh Legislative Assembly, and from 1980 to 1982, he served as a minister in the state cabinet. Afterwards, he switched party allegiance and joined TDP, which had been founded by Nandamuri Taraka Rama Rao, his father-in-law, whom he initially opposed. He gained the confidence of Rao, especially after helping thwart an INC attempt to oust Rao from his post as chief minister in 1984, becoming the party's general secretary. Naidu served as a TDP Member of the Legislative Assembly (MLA) from 1989 to 1995, during which period he became a high-profile opposition leader. In 1995, he became the Chief Minister of Andhra Pradesh after an intra-party coup against the leadership of Rao." | |
| # question="Who is Chandrababu Naidu?" | |
| def get_answer(file,question): | |
| context = load_text_from_file(file) | |
| answer=question_answer(context=context,question=question) | |
| return answer['answer'] | |
| gr.close_all() | |
| # demo = gr.Interface(fn=summary, inputs="text",outputs="text") | |
| demo = gr.Interface(fn=get_answer, | |
| inputs=[gr.File(label="Upload text file"), gr.Textbox(label="Ask you Question",lines=5)], | |
| outputs=[gr.Textbox(label="Answer to your question",lines=2)], | |
| title="AI ROBO HUB Consulting Services Pvt. Ltd.", | |
| description="THIS ARTIFICIAL INTELLIGENCE APPLICATION WILL BE USED TO ANSWER THE QUESTION BASED ON THE CONTEXT / DOCUMENT PROVIDED. - For More Details: +91 7893688993 | chrao@airobohub.com") | |
| demo.launch() |