File size: 2,347 Bytes
9b3ff22
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b59b67d
e714fad
5f66163
9b3ff22
 
 
 
 
 
 
 
 
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
59
60
import json
import time
import os
from datetime import datetime

import gradio as gr
import requests

url = os.environ.get('URL')

def process_and_render(prompt, name, type, gender, nationality, min_age, max_age, major, interest):
    payload = {
        "prompt": prompt,
        "name": name,
        "type": type,
        "gender": gender,
        "nationality": nationality,
        "min_age": min_age,
        "max_age": max_age,
        "major": major,
        "interest": interest
    }
    response = requests.post(url, json=payload)
    
    if response.status_code == 200:
        print("Success!")
        # print(response.json())  
        return response.json()['data']
    else:
        print(f"Failed with status code: {response.status_code}")
        print(response.text)  
        return response.text
    

with gr.Blocks() as demo:
    gr.Markdown("# SNU Buddy Spring 2024 Search Engine")
    
    prompt = gr.Textbox(label="Enter your prompt", placeholder="Who is the most out going?")

    with gr.Row():
        name = gr.Textbox(label="Name")
        type = gr.CheckboxGroup(label="Student Type", choices=["SNU", "Exchange"])
        gender = gr.CheckboxGroup(label="Gender", choices=["Male", "Female"])
    with gr.Row():
        min_age = gr.Number(label="Minimum Age", value=0)  
        max_age = gr.Number(label="Maximum Age", value=100)
    with gr.Row():
        nationality = gr.CheckboxGroup(label="Nationality", choices=["South Korea", "United States of America", "Australia", "Canada", "China", "France", "Germany", "Ireland", "Japan", "New Zealand", "Norway", "Singapore", "Sweden", "Switzerland", "United Kingdom"])
        major = gr.CheckboxGroup(label="Major", choices=["Asia", "Art", "Business", "Bio", "Computer Science", "Economics", "Engineering", "Film", "History", "International", "Korea", "Law", "Linguistics",  "Math", "Media", "Medicine", "Philosophy", "Politic"])
        interest = gr.Textbox(label="Interests & Hobbies (Separate each keyword with a comma)", placeholder="sports, music, movie")
    
    submit = gr.Button("Search")
    
    html_output = gr.HTML()  # Output as HTML 

    submit.click(process_and_render, inputs=[prompt, name, type, gender, nationality, min_age, max_age, major, interest], outputs=[html_output])

# This line is key for generating a public URL  
demo.launch()