skydheere commited on
Commit
4d4837c
·
1 Parent(s): b092406

new update

Browse files
Files changed (3) hide show
  1. app.py +39 -4
  2. index.json +0 -0
  3. requirement.txt +2 -0
app.py CHANGED
@@ -1,7 +1,42 @@
 
 
 
 
1
  import gradio as gr
 
 
2
 
3
- def greet(name):
4
- return "Hello From Hormuud" + name + "!!"
5
 
6
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from gpt_index import SimpleDirectoryReader, GPTListIndex, GPTSimpleVectorIndex, LLMPredictor, PromptHelper
2
+ from langchain import OpenAI
3
+ # from gpt_index import LLMPredictor, ServiceContext
4
+ from gpt_index import LLMPredictor, ServiceContext
5
  import gradio as gr
6
+ import sys
7
+ import os
8
 
9
+
 
10
 
11
+ def construct_index(directory_path):
12
+ max_input_size = 4096
13
+ num_outputs = 512
14
+ max_chunk_overlap = 20
15
+ chunk_size_limit = 600
16
+
17
+ prompt_helper = PromptHelper(max_input_size, num_outputs, max_chunk_overlap, chunk_size_limit=chunk_size_limit)
18
+
19
+ llm_predictor = LLMPredictor(llm=OpenAI(temperature=0.9, model_name="text-davinci-003", max_tokens=num_outputs))
20
+
21
+ documents = SimpleDirectoryReader(directory_path).load_data()
22
+ service_context = ServiceContext.from_defaults(llm_predictor=llm_predictor, prompt_helper=prompt_helper)
23
+
24
+ index = GPTSimpleVectorIndex.from_documents(documents, service_context=service_context)
25
+ # index = GPTSimpleVectorIndex(documents, llm_predictor=llm_predictor, prompt_helper=prompt_helper)
26
+
27
+ index.save_to_disk('index.json')
28
+
29
+ return index
30
+
31
+ def chatbot(input_text):
32
+ index = GPTSimpleVectorIndex.load_from_disk('index.json')
33
+ response = index.query(input_text, response_mode="compact")
34
+ return response.response
35
+
36
+ iface = gr.Interface(fn=chatbot,
37
+ inputs=gr.inputs.Textbox(lines=7, label="Enter your text"),
38
+ outputs="text",
39
+ title="Hormuud Services")
40
+
41
+ # index = construct_index("docs")
42
+ iface.launch(share=True)
index.json ADDED
The diff for this file is too large to render. See raw diff
 
requirement.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ gpt_index
2
+ langchain