File size: 2,262 Bytes
d435c86
f5b9b37
 
d435c86
 
 
 
 
 
 
 
 
 
 
 
807df8d
 
 
 
5839dd1
 
 
 
 
 
 
 
e428b8d
5839dd1
 
e428b8d
 
5839dd1
 
e428b8d
5839dd1
 
 
 
 
 
e428b8d
5839dd1
 
 
807df8d
 
 
5d2cd5f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
807df8d
d435c86
 
 
807df8d
d435c86
 
 
807df8d
5d2cd5f
807df8d
 
 
 
efd2301
 
 
 
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import requests
import gradio as gr

def get_text_response(prompt):
    api_url = "http://35.233.231.20:5002/api/generate"
    data_payload = {
        "model": "llama2",
        "prompt": prompt,
        "stream": False
    }
    response = requests.post(api_url, json=data_payload)
    response_json = response.json()
    text_response = response_json.get("response", "No response received.")
    return text_response

def clear_chat():
    return "", ""

css = """
<style>
    .header {
        font-size: 24px;
        font-weight: bold;
        text-align: center;
        margin-top: 1rem;
        margin-bottom: 2rem;
    }
    button.gr-button {
        background-color: #7D3C98;
        color: white;
        padding: 0.5rem 1rem;
        font-size: 1rem;
        border-radius: 0.5rem;
    }
    button.gr-button:hover {
        background-color: #6C3483;
    }
    .acknowledgments {
        margin-top: 20px;
        text-align: center;
    }
    .gr-textbox, button.gr-button, .gr-output {
        height: 2.5rem;
    }
</style>
"""

with gr.Blocks(css=css) as demo:
    gr.HTML(
        """
            <div style="text-align: center; max-width: 650px; margin: 0 auto; padding-top: 7px;">
              <div
                style="
                  display: inline-flex;
                  align-items: center;
                  gap: 0.8rem;
                  font-size: 1.75rem;
                "
              >
                <h1 style="font-weight: 900; margin-bottom: 7px;">
                  Fair Compute Llama-2 Chat
                </h1>
              </div>
            </div>
        """
    )
    
    with gr.Row():
        prompt = gr.Textbox(label="Enter your prompt")
        submit_button = gr.Button("Submit")
        clear_button = gr.Button("Clear")
    output = gr.Textbox(label="Response")

    submit_button.click(fn=get_text_response, inputs=prompt, outputs=output)
    clear_button.click(fn=clear_chat, inputs=[], outputs=[prompt, output])
    gr.HTML(
        """
        <div class="acknowledgments">
            <p>Run AI models on your home computers, powered by <a href="https://faircompute.com/" style="text-decoration: underline;" target="_blank">FairCompute</a></p>
        </div>
        """
    )

demo.launch()