|
import os |
|
from llama_index.core import StorageContext, load_index_from_storage, ServiceContext |
|
from github import Github |
|
import datetime |
|
import gradio as gr |
|
|
|
|
|
|
|
exec(os.environ.get('storage_context')) |
|
|
|
|
|
exec(os.environ.get('logs_context')) |
|
project_name = "PharmaWise 3.6 - demo Prospecto Gen茅rico Vortioxetina V2C_STREAM" |
|
|
|
|
|
|
|
def predict(message): |
|
|
|
|
|
|
|
respuesta = engine.query(prompt + message) |
|
|
|
|
|
partial_message = "" |
|
for chunk in respuesta.response_gen: |
|
partial_message += chunk |
|
yield partial_message |
|
|
|
|
|
|
|
|
|
def commit_to_github(message, response): |
|
if github_token: |
|
g = Github(github_token) |
|
repo = g.get_repo(repo_name) |
|
|
|
|
|
current_date = datetime.datetime.now().strftime("%Y-%m") |
|
|
|
|
|
file_name = f"{project_name}/{current_date}-{project_name}.txt" |
|
|
|
|
|
commit_message = f"Actualizaci贸n de {current_date}" |
|
|
|
content = f"({datetime.datetime.now().strftime('%d/%m/%Y %H:%M')})\nPregunta: {message}\nRespuesta: {response}\n----------\n" |
|
|
|
|
|
try: |
|
|
|
existing_file = repo.get_contents(file_name) |
|
existing_content = existing_file.decoded_content.decode('utf-8') |
|
new_content = f"{existing_content}{content}" |
|
repo.update_file(file_name, commit_message, new_content, existing_file.sha, branch="main") |
|
except: |
|
|
|
repo.create_file(file_name, commit_message, content, branch="main") |
|
|
|
|
|
|
|
gr.Interface( |
|
fn=predict, |
|
inputs=gr.Textbox(placeholder="Escribe una pregunta...", label="Pregunta"), |
|
outputs=gr.Textbox(label="Respuesta"), |
|
title=project_name, |
|
description="Realiza preguntas a tus datos y obt茅n respuestas en espa帽ol.", |
|
theme='sudeepshouche/minimalist', |
|
examples=["驴Cuales son las contraindicaciones y como se toma?"], |
|
cache_examples=True, |
|
).launch() |
|
|