File size: 1,746 Bytes
9ee33af
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
48
49
50
51
52
53
54
55
56
57
58
import os
import sys

import gradio as gr

# Get the directory of the current script
current_dir = os.path.dirname(__file__)

# Move up to the parent directory and then to the cousin folder
cousin_folder = os.path.join(current_dir, "..", "b1_rag_fns")

# Add cousin folder to sys.path so it can be imported
sys.path.append(os.path.abspath(cousin_folder))

from b1_all_rag_fns import do_rag
from dotenv import load_dotenv


def gr_ch_if(user_input: str, history):
    oai_api_key = os.getenv("OPENAI_API_KEY")
    response, _ = do_rag(
        user_input,
        stream=False,
        n_results=3,
        model_name="gpt-4o-mini",
        oai_api_key=oai_api_key,
    )
    return response


with gr.Blocks() as demo:
    gr.ChatInterface(
        fn=gr_ch_if,
        # type="messages",
        title="Use Gradio to Run RAG on the previous R/Gov Talks - Chat Interface 1",
    )

    # Add the static markdown at the bottom
    gr.Markdown(
        """
        This Gradio app was created for Alan Feder's [talk at the 2024 R/Gov Conference](https://rstats.ai/gov.html). \n\n The Github repository that houses all the code is [here](https://github.com/AlanFeder/rgov-2024) -- feel free to fork it and use it on your own!
        """
    )
    gr.Divider()
    gr.Subheader("Contact me!")
    gr.Image("AJF_Headshot.jpg", width=60)
    gr.Markdown(
        """
        [Email](mailto:[email protected]) | [Website](https://www.alanfeder.com/) | [LinkedIn](https://www.linkedin.com/in/alanfeder/) | [GitHub](https://github.com/AlanFeder)
        """
    )

if __name__ == "__main__":
    demo.launch(
        share=True,
        favicon_path="https://raw.githubusercontent.com/AlanFeder/rgov-2024/refs/heads/main/favicon_io/favicon.ico",
    )