noddysnots commited on
Commit
816f539
Β·
verified Β·
1 Parent(s): 2f23ac1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -26
app.py CHANGED
@@ -1,55 +1,50 @@
1
  import gradio as gr
2
- from transformers import pipeline
 
3
 
4
- # πŸ”Ή Load Qwen2.5-14B-Instruct-1M with a pipeline
5
- pipe = pipeline("text-generation", model="Qwen/Qwen2.5-14B-Instruct-1M")
 
 
6
 
7
- # 🎯 Function to extract interests from user input
 
 
8
  def extract_interests(text):
9
- prompt = f"Extract 3-5 relevant interests from this request: '{text}'. Focus on hobbies and product preferences."
10
-
11
- response = pipe(prompt, max_length=50, num_return_sequences=1)
12
  interests = response[0]["generated_text"].replace(prompt, "").strip()
13
-
14
  return interests.split(", ")
15
 
16
  # 🎁 Web search for gift suggestions
17
  def search_gifts(interests):
18
  query = "+".join(interests)
19
- amazon_url = f"https://www.amazon.in/s?k={query}"
20
- flipkart_url = f"https://www.flipkart.com/search?q={query}"
21
- igp_url = f"https://www.igp.com/search?q={query}"
22
- indiamart_url = f"https://dir.indiamart.com/search.mp?ss={query}"
23
-
24
  return {
25
- "Amazon": amazon_url,
26
- "Flipkart": flipkart_url,
27
- "IGP": igp_url,
28
- "IndiaMart": indiamart_url
29
  }
30
 
31
  # 🎯 Main function for gift recommendation
32
  def recommend_gifts(text):
33
  if not text:
34
  return "Please enter a description."
35
-
36
  interests = extract_interests(text)
37
  links = search_gifts(interests)
38
 
39
- return {
40
- "Predicted Interests": interests,
41
- "Gift Suggestions": links
42
- }
43
 
44
- # 🎨 Gradio UI for easy interaction
45
  demo = gr.Interface(
46
  fn=recommend_gifts,
47
  inputs="text",
48
  outputs="json",
49
- title="🎁 AI Gift Recommender",
50
- description="Enter details about the person you are buying a gift for, and get personalized suggestions with shopping links!",
51
  )
52
 
53
  # πŸš€ Launch Gradio App
54
  if __name__ == "__main__":
55
- demo.launch()
 
1
  import gradio as gr
2
+ from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
3
+ import torch
4
 
5
+ # πŸ”Ή Load Llama 3 - 7B model
6
+ model_name = "meta-llama/Meta-Llama-3-7B-Instruct"
7
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
8
+ model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.float16, device_map="auto")
9
 
10
+ pipe = pipeline("text-generation", model=model, tokenizer=tokenizer, max_new_tokens=100)
11
+
12
+ # 🎯 Extract interests from user input
13
  def extract_interests(text):
14
+ prompt = f"Extract 3-5 keywords from this: '{text}' (focus on hobbies & products)."
15
+ response = pipe(prompt)
 
16
  interests = response[0]["generated_text"].replace(prompt, "").strip()
 
17
  return interests.split(", ")
18
 
19
  # 🎁 Web search for gift suggestions
20
  def search_gifts(interests):
21
  query = "+".join(interests)
 
 
 
 
 
22
  return {
23
+ "Amazon": f"https://www.amazon.in/s?k={query}",
24
+ "Flipkart": f"https://www.flipkart.com/search?q={query}",
25
+ "IGP": f"https://www.igp.com/search?q={query}",
26
+ "IndiaMart": f"https://dir.indiamart.com/search.mp?ss={query}",
27
  }
28
 
29
  # 🎯 Main function for gift recommendation
30
  def recommend_gifts(text):
31
  if not text:
32
  return "Please enter a description."
33
+
34
  interests = extract_interests(text)
35
  links = search_gifts(interests)
36
 
37
+ return {"Predicted Interests": interests, "Gift Suggestions": links}
 
 
 
38
 
39
+ # 🎨 Gradio UI
40
  demo = gr.Interface(
41
  fn=recommend_gifts,
42
  inputs="text",
43
  outputs="json",
44
+ title="🎁 AI Gift Recommender (Llama 3 - 7B)",
45
+ description="Enter details about the person and get personalized gift suggestions with shopping links!",
46
  )
47
 
48
  # πŸš€ Launch Gradio App
49
  if __name__ == "__main__":
50
+ demo.launch()