File size: 1,193 Bytes
d450b8c
 
 
 
 
f5af3f3
d450b8c
 
f5af3f3
d450b8c
 
f5af3f3
d450b8c
 
 
f5af3f3
 
d450b8c
f5af3f3
d450b8c
 
 
 
 
 
 
 
 
 
 
 
f5af3f3
 
d450b8c
 
 
 
 
 
f5af3f3
d450b8c
f5af3f3
d450b8c
f5af3f3
d450b8c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from shiny import App, ui, reactive, render, req
import nest_asyncio
import json
from scrapegraphai.graphs import SearchGraph
import streamlit as st

# Access your API keys securely
OPENAI_API_KEY = st.secrets["OPENAI_API_KEY"]

# Apply necessary settings for asyncio compatibility
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()