CobaltZvc commited on
Commit
16d2422
β€’
1 Parent(s): d34f066

Upload Standards.py

Browse files
Files changed (1) hide show
  1. Standards.py +82 -0
Standards.py ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import openai
2
+ import gradio as gr
3
+ from serpapi import GoogleSearch
4
+
5
+ openai.api_key = "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"
6
+
7
+ messages = [
8
+ {
9
+ "role": "system",
10
+ "content": '''
11
+ You are Dr. Vivek a professional Safety Standards Expert, Standards professional with a deep understanding
12
+ of the various standards and their applications in different industries, as well as the processes for developing
13
+ and revising standards. Standards experts may work in industries such as engineering, manufacturing,
14
+ or quality assurance, and may be involved in developing, implementing, or auditing compliance with standards. You have
15
+ great attention to detail, Analytical skills, Critical thinking, Knowledge of regulatory requirements, good Problem-solving capability.
16
+ '''},
17
+ ]
18
+
19
+ def g_search(prompt_):
20
+ try:
21
+ params = {
22
+ "q": prompt_,
23
+ "location": "Bengaluru, Karnataka, India",
24
+ "hl": "hi",
25
+ "gl": "in",
26
+ "google_domain": "google.co.in",
27
+ "api_key": "7d28061bfff8ec82f25ab323d8a73d884bb8c8ebc84a6dc716d8b486191ba2e6"
28
+ }
29
+
30
+ search = GoogleSearch(params)
31
+ results = search.get_dict()
32
+ organic_results = results["organic_results"]
33
+
34
+ snippets = ""
35
+ counter = 1
36
+ for item in organic_results:
37
+ snippets += str(counter) + ". " + item.get("snippet", "") + '\n' + item['about_this_result']['source']['source_info_link'] + '\n'
38
+ counter += 1
39
+
40
+ response = openai.Completion.create(
41
+ model="text-davinci-003",
42
+ prompt=f'''following are snippets from google search with these as knowledge base only answer questions and print reference link as well followed by answer. \n\n {snippets}\n\n question-{prompt_}\n\nAnswer-''',
43
+ temperature=0.49,
44
+ max_tokens=256,
45
+ top_p=1,
46
+ frequency_penalty=0,
47
+ presence_penalty=0)
48
+
49
+ string_temp = response.choices[0].text
50
+ return string_temp
51
+
52
+ except:
53
+ pass
54
+
55
+ def openai_chat(prompt_):
56
+ if prompt_:
57
+ messages.append(
58
+ {"role": "user", "content": prompt_},
59
+ )
60
+ chat_completion = openai.ChatCompletion.create(
61
+ model="gpt-3.5-turbo", messages=messages
62
+ )
63
+ reply = chat_completion.choices[0].message.content
64
+
65
+ if ("Oh!" in reply or "Internet" in reply):
66
+ res = g_search(prompt_)
67
+ return res.strip()
68
+ else:
69
+ return reply.strip()
70
+
71
+ def saab(input, hist=[]):
72
+ _user_ = "πŸ‘€: "
73
+ _saab_ = "πŸŽ–οΈπŸ§“πŸ»πŸŽ–οΈ: "
74
+ output = openai_chat(input)
75
+ hist.append((_user_+input, _saab_+output))
76
+ return hist, hist
77
+
78
+ gr.Interface(fn=saab,
79
+ inputs=["text","state"],
80
+ outputs=["chatbot","state"],
81
+ title="SSB Virtual Coaching",
82
+ description="Ask your doubts to Col. sir! (Dev. Vishwesh V Bhat)").launch(share=True)