File size: 1,006 Bytes
cde1f49
12cca3e
 
 
 
 
cde1f49
 
12cca3e
 
 
cde1f49
 
12cca3e
 
cde1f49
 
 
 
 
12cca3e
cde1f49
12cca3e
cde1f49
12cca3e
 
cde1f49
 
 
 
 
 
 
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

import openai
import gradio as gr
from full_chain import get_response
import os

api_key = os.getenv("OPENAI_API_KEY")
client = openai.OpenAI(api_key=api_key)


def create_hyperlink(url, title, domain):
    return f"<a href='{url}'>{title}</a>" + " (" + domain + ")"


def predict(message, history):
    print("get_responses: ")
    # print(get_response(message, rerank_type="crossencoder"))
    responder, links, titles, domains = get_response(message, rerank_type="crossencoder")
    for i in range(len(links)):
        links[i] = create_hyperlink(links[i], titles[i], domains[i])

    out = responder + "\n" + "\n".join(links)

    return out


gr.ChatInterface(predict,
                examples = [
                    "How many Americans Smoke?",
                    "What are some measures taken by the Indian Government to reduce the smoking population?",
                    "Does smoking negatively affect my health?"
                ]
                ).launch()