Spaces:
Runtime error
Runtime error
from pathlib import Path | |
import gradio as gr | |
from langchain import FAISS | |
from langchain.embeddings import OpenAIEmbeddings | |
import os | |
embeddings = OpenAIEmbeddings() | |
faiss_path = Path(__file__).parent / "faiss_index_03" | |
docsearch = FAISS.load_local(faiss_path, embeddings) | |
def generate_outputs(query: str, k: int): | |
outputs = [] | |
docs_and_scores = docsearch.similarity_search_with_score(query, k=k) | |
for doc, score in docs_and_scores: | |
output_text = f"{doc.page_content} + \n Score: {score:.2f}" | |
outputs.append(output_text) | |
return "\n---------------------------------------------------------\n" \ | |
"---------------------------------------------------------\n" \ | |
"---------------------------------------------------------\n".join(outputs) | |
# Define input/output interfaces and options | |
iface = gr.Interface( | |
fn=generate_outputs, | |
inputs=[ | |
gr.Textbox(label="Enter your text", value="Sample text", lines=2), | |
gr.Slider(label="Number of outputs", minimum=1, maximum=12, value=4) | |
], | |
outputs=[ | |
gr.Textbox(label="Generated Outputs") | |
], | |
title="Text Generation App", | |
description="Enter your text and choose the number of outputs you'd like to generate" | |
) | |
# Launch the Gradio app | |
iface.launch() |