Tulika2000 commited on
Commit
820b8d2
·
verified ·
1 Parent(s): 3e08a49

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -14
app.py CHANGED
@@ -1,14 +1,9 @@
1
  # -*- coding: utf-8 -*-
2
- """app.ipynb
3
-
4
- Automatically generated by Colab.
5
-
6
- Original file is located at
7
- https://colab.research.google.com/drive/1vaVKGg6ycx5H06dSgRVN0d5CzcJquou5
8
  """
9
 
10
  import os
11
- from langchain.chains import LLMChain
12
  from langchain_core.prompts import PromptTemplate
13
  from langchain_groq import ChatGroq
14
  from googleapiclient.discovery import build
@@ -44,8 +39,8 @@ prompt_template = PromptTemplate(
44
  )
45
  )
46
 
47
- # Create the LLMChain
48
- chain = LLMChain(llm=llm, prompt=prompt_template)
49
 
50
  # Function to fetch YouTube videos with clickable links
51
  def search_youtube_videos(query, max_results=2):
@@ -80,13 +75,13 @@ def get_youtube_links(age_range):
80
  # Safety Advice Function
81
  def safety_advice(user_input, age_range):
82
  if not user_input.strip():
83
- return "⚠️ Please enter a situation to receive advice.", "<p></p>" # Empty HTML for videos
84
 
85
- response = chain.run(user_input=user_input, age_range=age_range)
86
  links_html = get_youtube_links(age_range)
87
-
88
  return f"{response}", links_html # Markdown for text, HTML for videos
89
-
90
  # Function to clear fields
91
  def clear_fields():
92
  return "", "30+ (Adult)", "", ""
@@ -119,4 +114,4 @@ with gr.Blocks() as app:
119
  generate_button.click(safety_advice, inputs=[situation_input, age_range_input], outputs=[advice_output, video_output])
120
  clear_button.click(clear_fields, inputs=[], outputs=[situation_input, age_range_input, advice_output, video_output])
121
 
122
- app.launch(share=True)
 
1
  # -*- coding: utf-8 -*-
2
+ """
3
+ SheGuard: Personal Safety Advisor
 
 
 
 
4
  """
5
 
6
  import os
 
7
  from langchain_core.prompts import PromptTemplate
8
  from langchain_groq import ChatGroq
9
  from googleapiclient.discovery import build
 
39
  )
40
  )
41
 
42
+ # Create the chain using LCEL (LangChain Expression Language)
43
+ chain = prompt_template | llm
44
 
45
  # Function to fetch YouTube videos with clickable links
46
  def search_youtube_videos(query, max_results=2):
 
75
  # Safety Advice Function
76
  def safety_advice(user_input, age_range):
77
  if not user_input.strip():
78
+ return "⚠️ Please enter a situation to receive advice.", "<p></p>"
79
 
80
+ response = chain.invoke({"user_input": user_input, "age_range": age_range}).content
81
  links_html = get_youtube_links(age_range)
82
+
83
  return f"{response}", links_html # Markdown for text, HTML for videos
84
+
85
  # Function to clear fields
86
  def clear_fields():
87
  return "", "30+ (Adult)", "", ""
 
114
  generate_button.click(safety_advice, inputs=[situation_input, age_range_input], outputs=[advice_output, video_output])
115
  clear_button.click(clear_fields, inputs=[], outputs=[situation_input, age_range_input, advice_output, video_output])
116
 
117
+ app.launch(share=True)