|
from shiny import App, ui, reactive, render, req |
|
import nest_asyncio |
|
import json |
|
from scrapegraphai.graphs import SearchGraph |
|
import streamlit as st |
|
|
|
|
|
OPENAI_API_KEY = st.secrets["OPENAI_API_KEY"] |
|
|
|
|
|
nest_asyncio.apply() |
|
|
|
app_ui = ui.page_fluid( |
|
ui.input_text("prompt", "Enter your query:", value="List me all the attributes of 'cannabis strain'."), |
|
ui.output_text_verbatim("results") |
|
) |
|
|
|
def server(input, output, session): |
|
@reactive.Calc |
|
def get_results(): |
|
graph_config = { |
|
"llm": { |
|
"api_key": OPENAI_API_KEY, |
|
"model": "gpt-3.5-turbo", |
|
"temperature": 0, |
|
}, |
|
} |
|
|
|
search_graph = SearchGraph( |
|
prompt=input.prompt(), |
|
config=graph_config |
|
) |
|
|
|
try: |
|
result = search_graph.run() |
|
output = json.dumps(result, indent=2) |
|
return output |
|
except Exception as e: |
|
return f"An error occurred: {e}" |
|
|
|
output.results <- render.text(lambda: get_results()) |
|
|
|
app = App(app_ui, server) |
|
|
|
if __name__ == "__main__": |
|
app.run() |
|
|