sayed010 commited on
Commit
76678f3
·
verified ·
1 Parent(s): eb1b33c

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +75 -0
app.py ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ !pip install -q gradio
2
+ !pip install -q groq
3
+ import gradio as gr
4
+ from groq import Groq
5
+ import os
6
+ os.environ["GROQ_API_KEY"] ="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"
7
+ # Set your Groq API key as an environment variable (e.g., in Colab: import os; os.environ["GROQ_API_KEY"] = "your_actual_groq_api_key_here")
8
+ client = Groq(api_key=os.environ.get("GROQ_API_KEY"))
9
+
10
+ SYSTEM_PROMPT = """You are an expert in premier league fantasy . Provide structured and insightful responses to queries
11
+ about players and coaches"""
12
+
13
+ def respond(message, history, model, temperature, max_tokens):
14
+ messages = [{"role": "system", "content": SYSTEM_PROMPT}]
15
+
16
+ for h in history:
17
+ messages.append({"role": "user", "content": h[0]})
18
+ if h[1]:
19
+ messages.append({"role": "assistant", "content": h[1]})
20
+
21
+ messages.append({"role": "user", "content": message})
22
+
23
+ try:
24
+ response = client.chat.completions.create(
25
+ model=model,
26
+ messages=messages,
27
+ temperature=temperature,
28
+ max_completion_tokens=max_tokens,
29
+ )
30
+ return response.choices[0].message.content
31
+ except Exception as e:
32
+ return f"Error: {str(e)}"
33
+
34
+ # ChatInterface with additional inputs for parameters
35
+ demo = gr.ChatInterface(
36
+ fn=respond,
37
+ title="🎬 premier league fantasy Generator AI",
38
+ description="Be the hero of the Week!",
39
+ additional_inputs=[
40
+ gr.Dropdown(
41
+ choices=[
42
+ "llama-3.3-70b-versatile",
43
+ "llama-3.1-8b-instant",
44
+ ],
45
+ value="llama-3.3-70b-versatile",
46
+ label="Model",
47
+ info="Select the AI model to use"
48
+ ),
49
+ gr.Slider(
50
+ minimum=0,
51
+ maximum=2,
52
+ value=0.9,
53
+ step=0.1,
54
+ label="Temperature",
55
+ info="Controls randomness. Lower = more focused, Higher = more creative"
56
+ ),
57
+ gr.Slider(
58
+ minimum=256,
59
+ maximum=8192,
60
+ value=2048,
61
+ step=256,
62
+ label="Max Tokens",
63
+ info="Maximum length of the response"
64
+ ),
65
+ ],
66
+ examples=[
67
+ ["what is the best player in this week"],
68
+ ["which player should I captin this week"],
69
+ ["Give me the perfect Team formation this week "],
70
+ ],
71
+ theme="soft",
72
+ )
73
+
74
+ if __name__ == "__main__":
75
+ demo.launch()