Spaces:
Runtime error
Runtime error
Commit ·
46899a3
1
Parent(s): b1f5f3d
Upload 5 files
Browse files
biochatprototipo/app.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from gpt_index import SimpleDirectoryReader, GPTListIndex, GPTSimpleVectorIndex, LLMPredictor, PromptHelper
|
| 2 |
+
from langchain.chat_models import ChatOpenAI
|
| 3 |
+
import gradio as gr
|
| 4 |
+
import sys
|
| 5 |
+
import os
|
| 6 |
+
|
| 7 |
+
os.environ["OPENAI_API_KEY"] = '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'
|
| 8 |
+
|
| 9 |
+
def construct_index(directory_path):
|
| 10 |
+
max_input_size = 4096
|
| 11 |
+
num_outputs = 512
|
| 12 |
+
max_chunk_overlap = 20
|
| 13 |
+
chunk_size_limit = 600
|
| 14 |
+
|
| 15 |
+
prompt_helper = PromptHelper(max_input_size, num_outputs, max_chunk_overlap, chunk_size_limit=chunk_size_limit)
|
| 16 |
+
|
| 17 |
+
llm_predictor = LLMPredictor(llm=ChatOpenAI(temperature=0.7, model_name="gpt-3.5-turbo", max_tokens=num_outputs))
|
| 18 |
+
|
| 19 |
+
documents = SimpleDirectoryReader(directory_path).load_data()
|
| 20 |
+
|
| 21 |
+
index = GPTSimpleVectorIndex(documents, llm_predictor=llm_predictor, prompt_helper=prompt_helper)
|
| 22 |
+
|
| 23 |
+
index.save_to_disk('index.json')
|
| 24 |
+
|
| 25 |
+
return index
|
| 26 |
+
|
| 27 |
+
def chatbot(input_text):
|
| 28 |
+
index = GPTSimpleVectorIndex.load_from_disk('index.json')
|
| 29 |
+
response = index.query(input_text, response_mode="compact")
|
| 30 |
+
return response.response
|
| 31 |
+
|
| 32 |
+
iface = gr.Interface(fn=chatbot,
|
| 33 |
+
inputs=gr.components.Textbox(lines=7, label="Faça sua pergunta"),
|
| 34 |
+
outputs=gr.components.Textbox( label="Resposta personalizada"),
|
| 35 |
+
title="BioChat")
|
| 36 |
+
|
| 37 |
+
index = construct_index("docs")
|
| 38 |
+
iface.launch(share=True)
|
biochatprototipo/docs/CAPA3CAP6.pdf
ADDED
|
Binary file (351 kB). View file
|
|
|
biochatprototipo/docs/cap1cap2..pdf
ADDED
|
Binary file (181 kB). View file
|
|
|
biochatprototipo/flagged/log.csv
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Faça sua pergunta,Resposta personalizada,flag,username,timestamp
|
| 2 |
+
,"'
|
| 3 |
+
Estatística é o ramo da matemática que se ocupa da coleta, organização, análise, interpretação e apresentação de dados. É usada para descobrir padrões e tendências, para tomar decisões e para prever resultados. Originalmente, foi desenvolvida para ajudar os governos a contar com quantas pessoas eles poderiam contar para conquistar novos territórios ou para se defender de agressores.",,,2023-08-27 21:33:05.323032
|
| 4 |
+
,,,,2023-08-27 22:08:05.565272
|
biochatprototipo/index.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|