Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from groq import Groq
|
3 |
+
|
4 |
+
def generate_response(prompt):
|
5 |
+
client = Groq(api_key="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") # Replace with your actual API key
|
6 |
+
completion = client.chat.completions.create(
|
7 |
+
model="llama3-8b-8192",
|
8 |
+
messages=[
|
9 |
+
{
|
10 |
+
"role": "system",
|
11 |
+
"content": (
|
12 |
+
"answer to every question as if you are a guy named vijayraj who is from Bangalore. "
|
13 |
+
"vijayraj loves to play volleyball. he is a big fan of film actor 'Darshan', who is also known as 'd boss'. "
|
14 |
+
"before answering any questions vijayraj screams 'elvishhh bhaii!'. vijayraj likes to go to the gym and talk about it. "
|
15 |
+
"his girlfriend's name is 'madhu'. he has an ambition to build a chicken farm in the future. always in between his words, "
|
16 |
+
"he adds 'nakkan'."
|
17 |
+
)
|
18 |
+
},
|
19 |
+
{"role": "user", "content": prompt},
|
20 |
+
],
|
21 |
+
temperature=1,
|
22 |
+
max_tokens=2900,
|
23 |
+
top_p=1,
|
24 |
+
stream=False,
|
25 |
+
stop=None,
|
26 |
+
)
|
27 |
+
|
28 |
+
# Accessing content correctly
|
29 |
+
response = completion.choices[0].message.content # Correct attribute access
|
30 |
+
return response
|
31 |
+
|
32 |
+
|
33 |
+
|
34 |
+
# Gradio Interface
|
35 |
+
def gradio_interface():
|
36 |
+
with gr.Blocks() as demo:
|
37 |
+
# Title and Image
|
38 |
+
gr.Markdown("## Chat with Vijayraj - The Gym Buff & Chicken Farm Enthusiast")
|
39 |
+
gr.Image("https://via.placeholder.com/600x200.png?text=Welcome+to+Vijayraj's+Chatbot") # Replace with your image URL or path.
|
40 |
+
|
41 |
+
# Input and Output
|
42 |
+
with gr.Row():
|
43 |
+
user_input = gr.Textbox(label="Your Question", placeholder="Ask Vijayraj anything!")
|
44 |
+
with gr.Row():
|
45 |
+
response_output = gr.Textbox(label="Vijayraj's Response", lines=5)
|
46 |
+
|
47 |
+
# Buttons
|
48 |
+
with gr.Row():
|
49 |
+
submit_button = gr.Button("Ask Vijayraj")
|
50 |
+
clear_button = gr.Button("Clear")
|
51 |
+
|
52 |
+
# Functionality
|
53 |
+
submit_button.click(generate_response, inputs=[user_input], outputs=[response_output])
|
54 |
+
clear_button.click(lambda: "", inputs=[], outputs=[user_input, response_output])
|
55 |
+
|
56 |
+
return demo
|
57 |
+
|
58 |
+
# Launch the Interface
|
59 |
+
if __name__ == "__main__":
|
60 |
+
demo = gradio_interface()
|
61 |
+
demo.launch(debug=True)
|