UMAR798 commited on
Commit
b7526f0
·
verified ·
1 Parent(s): fe150cb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +66 -0
app.py CHANGED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gradio as gr
3
+ from groq import Groq
4
+
5
+ # Load API key from environment variable
6
+ GROQ_API_KEY = os.getenv("GROQ_API_KEY")
7
+
8
+ if not GROQ_API_KEY:
9
+ raise ValueError("Please set GROQ_API_KEY in your Hugging Face Space secrets.")
10
+
11
+ client = Groq(api_key=GROQ_API_KEY)
12
+
13
+ def generate_portfolio(name, skills, projects, tone):
14
+ prompt = f"""
15
+ Create a professional portfolio description.
16
+
17
+ Name: {name}
18
+ Skills: {skills}
19
+ Projects: {projects}
20
+ Tone: {tone}
21
+
22
+ The description should be engaging, clear, and suitable for a personal website.
23
+ """
24
+
25
+ try:
26
+ response = client.chat.completions.create(
27
+ model="llama-3.1-70b-versatile",
28
+ messages=[
29
+ {"role": "system", "content": "You are a professional content writer."},
30
+ {"role": "user", "content": prompt}
31
+ ],
32
+ temperature=0.7,
33
+ max_tokens=400
34
+ )
35
+
36
+ return response.choices[0].message.content
37
+
38
+ except Exception as e:
39
+ return f"Error: {str(e)}"
40
+
41
+
42
+ # Gradio UI
43
+ with gr.Blocks() as demo:
44
+ gr.Markdown("# 🚀 Portfolio Description Generator")
45
+
46
+ name = gr.Textbox(label="Your Name")
47
+ skills = gr.Textbox(label="Your Skills", placeholder="Python, ML, Web Dev")
48
+ projects = gr.Textbox(label="Your Projects", placeholder="Describe your work")
49
+ tone = gr.Dropdown(
50
+ ["Professional", "Casual", "Creative"],
51
+ label="Tone",
52
+ value="Professional"
53
+ )
54
+
55
+ output = gr.Textbox(label="Generated Description", lines=10)
56
+
57
+ btn = gr.Button("Generate")
58
+
59
+ btn.click(
60
+ fn=generate_portfolio,
61
+ inputs=[name, skills, projects, tone],
62
+ outputs=output
63
+ )
64
+
65
+ if __name__ == "__main__":
66
+ demo.launch()