Download app.py from TEMELJNI/FunkyChat: direct link, hf CLI and curl.
- Browser
- Download file 1.06 kB
-
https://huggingface.co/spaces/TEMELJNI/FunkyChat/resolve/main/app.py
- Command line
-
hf download hf://spaces/TEMELJNI/FunkyChat/app.py
-
curl -L -o app.py https://huggingface.co/spaces/TEMELJNI/FunkyChat/resolve/main/app.py
1.06 kB
| from gpt_index import SimpleDirectoryReader, GPTListIndex, GPTSimpleVectorIndex, LLMPredictor, PromptHelper | |
| from langchain import OpenAI | |
| import gradio as gr | |
| import sys | |
| import os | |
| os.environ["OPENAI_API_KEY"] = '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' | |
| def construct_index(directory_path): | |
| max_input_size = 4096 | |
| num_outputs = 512 | |
| max_chunk_overlap = 20 | |
| chunk_size_limit = 600 | |
| prompt_helper = PromptHelper(max_input_size, num_outputs, max_chunk_overlap, chunk_size_limit=chunk_size_limit) | |
| llm_predictor = LLMPredictor(llm=OpenAI(temperature=0.7, model_name='GPT4', max_tokens=num_outputs)) | |
| return index | |
| def chatbot(input_text): | |
| index = GPTSimpleVectorIndex.load_from_disk('index.json') | |
| response = index.query(input_text, response_mode="compact") | |
| return response.response | |
| iface = gr.Interface(fn=chatbot, | |
| inputs=gr.components.Textbox(lines=7, label="Enter your text"), | |
| outputs="text", | |
| title="Custom-trained AI Chatbot") | |
| iface.launch() |