rajsecrets0 commited on
Commit
77e952c
β€’
1 Parent(s): 52e90d7

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -0
app.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Load the Hugging Face model for question answering
5
+ qa_model = pipeline("question-answering")
6
+
7
+ # Function to handle PDF input and return chatbot responses
8
+ def chatbot_function(pdf_file):
9
+ # Your PDF processing logic here
10
+ # For simplicity, let's assume you convert the PDF to text
11
+ with open(pdf_file, "r", encoding="utf-8") as file:
12
+ pdf_text = file.read()
13
+
14
+ # Use the question answering model to get responses
15
+ question = "What is your question?"
16
+ answer = qa_model(question=question, context=pdf_text)
17
+
18
+ return answer["answer"]
19
+
20
+ # Gradio Interface
21
+ iface = gr.Interface(
22
+ fn=chatbot_function,
23
+ inputs=gr.File(type="file", label="Upload PDF File"),
24
+ outputs="text",
25
+ live=True,
26
+ title="Chatbot for PDF Documents",
27
+ description="Upload a PDF document and ask questions to the chatbot.",
28
+ )
29
+
30
+ # Launch the Gradio app
31
+ iface.launch()