Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -23,12 +23,12 @@ import pandas as pd
|
|
23 |
from llama_index import SimpleDirectoryReader, GPTListIndex, readers, GPTSimpleVectorIndex, LLMPredictor, PromptHelper
|
24 |
from langchain import OpenAI
|
25 |
from IPython.display import Markdown, display
|
26 |
-
#import streamlit as st
|
27 |
import gradio as gr
|
28 |
-
|
29 |
-
df = pd.read_excel('Shegardi_dataset.xlsx',sheet_name
|
30 |
-
#os.environ['OPENAI_API_KEY'] = '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'
|
31 |
os.environ['OPENAI_API_KEY'] = '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'
|
|
|
|
|
32 |
def construct_index(directory_path):
|
33 |
# set maximum input size
|
34 |
max_input_size = 4096
|
@@ -44,16 +44,16 @@ def construct_index(directory_path):
|
|
44 |
prompt_helper = PromptHelper(max_input_size, num_outputs, max_chunk_overlap, chunk_size_limit=chunk_size_limit)
|
45 |
|
46 |
documents = SimpleDirectoryReader(directory_path).load_data()
|
47 |
-
|
48 |
index = GPTSimpleVectorIndex(
|
49 |
documents, llm_predictor=llm_predictor, prompt_helper=prompt_helper
|
50 |
)
|
|
|
51 |
index.registry.add_type_to_struct(1, {"answer": str, "question": str})
|
52 |
index.save_to_disk('index.json')
|
53 |
-
|
54 |
return index
|
55 |
|
56 |
-
|
|
|
57 |
|
58 |
# Include other necessary imports here
|
59 |
|
@@ -62,7 +62,8 @@ def ask_ai(query):
|
|
62 |
response = index.query(query, response_mode="compact")
|
63 |
return response.response
|
64 |
|
65 |
-
iface = gr.Interface(fn=ask_ai, inputs="text", outputs="text",
|
|
|
66 |
description="Enter a question and get an answer from Shegardi.")
|
67 |
|
68 |
iface.launch()
|
|
|
23 |
from llama_index import SimpleDirectoryReader, GPTListIndex, readers, GPTSimpleVectorIndex, LLMPredictor, PromptHelper
|
24 |
from langchain import OpenAI
|
25 |
from IPython.display import Markdown, display
|
|
|
26 |
import gradio as gr
|
27 |
+
|
28 |
+
df = pd.read_excel('Shegardi_dataset.xlsx', sheet_name='dataset')
|
|
|
29 |
os.environ['OPENAI_API_KEY'] = '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'
|
30 |
+
|
31 |
+
|
32 |
def construct_index(directory_path):
|
33 |
# set maximum input size
|
34 |
max_input_size = 4096
|
|
|
44 |
prompt_helper = PromptHelper(max_input_size, num_outputs, max_chunk_overlap, chunk_size_limit=chunk_size_limit)
|
45 |
|
46 |
documents = SimpleDirectoryReader(directory_path).load_data()
|
|
|
47 |
index = GPTSimpleVectorIndex(
|
48 |
documents, llm_predictor=llm_predictor, prompt_helper=prompt_helper
|
49 |
)
|
50 |
+
# Fix for the error message
|
51 |
index.registry.add_type_to_struct(1, {"answer": str, "question": str})
|
52 |
index.save_to_disk('index.json')
|
|
|
53 |
return index
|
54 |
|
55 |
+
|
56 |
+
# construct_index("context_data/data")
|
57 |
|
58 |
# Include other necessary imports here
|
59 |
|
|
|
62 |
response = index.query(query, response_mode="compact")
|
63 |
return response.response
|
64 |
|
65 |
+
iface = gr.Interface(fn=ask_ai, inputs="text", outputs="text",
|
66 |
+
title="The following is a conversation with a human called Shegardi. Shegardi is helpful, precise, truthful, and very friendly. Also, Shegardi is an employee of Warba Bank, located in Kuwait. Shegardi will only use the information provided to him. ",
|
67 |
description="Enter a question and get an answer from Shegardi.")
|
68 |
|
69 |
iface.launch()
|