Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,9 +1,9 @@
|
|
|
|
1 |
import gradio as gr
|
|
|
2 |
from llama_index.llms.huggingface import HuggingFaceInferenceAPI
|
3 |
-
from llama_index.core import ChatPromptTemplate, Settings, StorageContext, load_index_from_storage, VectorStoreIndex, SimpleDirectoryReader
|
4 |
from llama_index.embeddings.huggingface import HuggingFaceEmbedding
|
5 |
-
from
|
6 |
-
import os
|
7 |
|
8 |
# Load environment variables
|
9 |
load_dotenv()
|
@@ -82,34 +82,27 @@ def handle_query(query):
|
|
82 |
print("Processing PDF ingestion from directory:", PDF_DIRECTORY)
|
83 |
data_ingestion_from_directory()
|
84 |
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
demo = gr.Interface(
|
106 |
-
fn=predict,
|
107 |
-
inputs=gr.Textbox(label="User Input", placeholder="Type your message here..."),
|
108 |
-
outputs=gr.Textbox(label="Bot Response", placeholder="Bot's response will appear here..."),
|
109 |
-
title="RedFernsTech Chatbot",
|
110 |
-
theme="compact",
|
111 |
-
live=True # Enables real-time updates
|
112 |
)
|
113 |
|
114 |
# Launch the Gradio interface
|
115 |
-
|
|
|
1 |
+
from dotenv import load_dotenv
|
2 |
import gradio as gr
|
3 |
+
from llama_index.core import StorageContext, load_index_from_storage, VectorStoreIndex, SimpleDirectoryReader, ChatPromptTemplate, Settings
|
4 |
from llama_index.llms.huggingface import HuggingFaceInferenceAPI
|
|
|
5 |
from llama_index.embeddings.huggingface import HuggingFaceEmbedding
|
6 |
+
from sentence_transformers import SentenceTransformer
|
|
|
7 |
|
8 |
# Load environment variables
|
9 |
load_dotenv()
|
|
|
82 |
print("Processing PDF ingestion from directory:", PDF_DIRECTORY)
|
83 |
data_ingestion_from_directory()
|
84 |
|
85 |
+
# Define the input and output components for the Gradio interface
|
86 |
+
input_component = gr.Textbox(
|
87 |
+
show_label=False,
|
88 |
+
placeholder="Ask me anything about the document..."
|
89 |
+
)
|
90 |
+
|
91 |
+
output_component = gr.Textbox()
|
92 |
+
|
93 |
+
# Function to handle queries
|
94 |
+
def chatbot_handler(query):
|
95 |
+
response = handle_query(query)
|
96 |
+
return response
|
97 |
+
|
98 |
+
# Create the Gradio interface
|
99 |
+
interface = gr.Interface(
|
100 |
+
fn=chatbot_handler,
|
101 |
+
inputs=input_component,
|
102 |
+
outputs=output_component,
|
103 |
+
title="RedfernsTech Q&A Chatbot",
|
104 |
+
description="Ask me anything about the uploaded document."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
)
|
106 |
|
107 |
# Launch the Gradio interface
|
108 |
+
interface.launch(share=True)
|