File size: 2,181 Bytes
48b3fd6
 
 
 
6a6da5b
48b3fd6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dade324
42d0701
48b3fd6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from groq import Groq

def generate_response(prompt):
    client = Groq(api_key="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")  # Replace with your actual API key
    completion = client.chat.completions.create(
        model="llama3-8b-8192",
        messages=[
            {
                "role": "system",
                "content": (
                    "answer to every question as if you are a guy named vijayraj who is from Bangalore. "
                    "vijayraj loves to play volleyball. he is a big fan of film actor 'Darshan', who is also known as 'd boss'. "
                    "before answering any questions vijayraj screams 'elvishhh bhaii!'. vijayraj likes to go to the gym and talk about it. "
                    "his girlfriend's name is 'madhu'. he has an ambition to build a chicken farm in the future. always in between his words, "
                    "he adds 'nakkan'."
                )
            },
            {"role": "user", "content": prompt},
        ],
        temperature=1,
        max_tokens=2900,
        top_p=1,
        stream=False,
        stop=None,
    )

    # Accessing content correctly
    response = completion.choices[0].message.content  # Correct attribute access
    return response



# Gradio Interface
def gradio_interface():
    with gr.Blocks() as demo:
        # Title and Image
        gr.Markdown("## weekend with vijayraj")
        gr.Image("Image.jpg")

        # Input and Output
        with gr.Row():
            user_input = gr.Textbox(label="Your Question", placeholder="Ask Vijayraj anything!")
        with gr.Row():
            response_output = gr.Textbox(label="Vijayraj's Response", lines=5)

        # Buttons
        with gr.Row():
            submit_button = gr.Button("Ask Vijayraj")
            clear_button = gr.Button("Clear")

        # Functionality
        submit_button.click(generate_response, inputs=[user_input], outputs=[response_output])
        clear_button.click(lambda: "", inputs=[], outputs=[user_input, response_output])

    return demo

# Launch the Interface
if __name__ == "__main__":
    demo = gradio_interface()
    demo.launch(debug=True)