Abhaykoul commited on
Commit
7fcf52f
1 Parent(s): 8018de6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -58
app.py CHANGED
@@ -1,7 +1,7 @@
1
- import g4f
2
- from webscout import WEBS
3
  from flask import Flask, jsonify, request
4
- import google.generativeai as palm
 
 
5
  app = Flask(__name__)
6
 
7
  @app.route('/search', methods=['POST'])
@@ -11,30 +11,15 @@ def WEBScout2_search_search():
11
  return jsonify({'error': 'Query parameter missing'})
12
 
13
  query = data['query']
14
- limit = data.get('limit', 10) # Default limit to 10 if not provided
15
- WEBS_instance = WEBS() # Instantiate WEBS without context manager
16
  responses = []
17
  for i, r in enumerate(WEBS_instance.text(query, region='wt-wt', safesearch='off', timelimit='y')):
18
- if i == limit: # Use the custom limit
19
  break
20
  responses.append(r)
21
  return jsonify(responses)
22
- # @app.route('/search', methods=['POST'])
23
-
24
- # def WEBScout2_search():
25
- # data = request.get_json()
26
- # if 'query' not in data:
27
- # return jsonify({'error': 'Query parameter missing'})
28
-
29
- # query = data['query']
30
- # WEBS_instance = WEBS() # Instantiate WEBS without context manager
31
- # responses = []
32
- # for i, r in enumerate(WEBS_instance.text(query, region='wt-wt', safesearch='off', timelimit='y')):
33
- # if i == 10: # Limiting the results to 10
34
- # break
35
- # responses.append(r)
36
- # return jsonify(responses)
37
-
38
  @app.route('/mws', methods=['POST'])
39
  def WEBScout_search():
40
  data = request.get_json()
@@ -42,14 +27,14 @@ def WEBScout_search():
42
  return jsonify({'error': 'Query parameter missing'})
43
 
44
  query = data['query']
45
- WEBS_instance = WEBS() # Instantiate WEBS without context manager
46
  responses = []
47
  for i, r in enumerate(WEBS_instance.text(query, region='wt-wt', safesearch='off', timelimit='y')):
48
- if i == 2: # Limiting the results to 10
49
  break
50
  responses.append(r)
51
  return jsonify(responses)
52
-
53
  @app.route('/health', methods=['GET'])
54
  def health_check():
55
  return jsonify({'status': 'ok'})
@@ -61,7 +46,7 @@ def WEBScout_videos():
61
  return jsonify({'error': 'Keywords parameter missing'})
62
 
63
  keywords = params['keywords']
64
- WEBS_instance = WEBS() # Instantiate WEBS without context manager
65
  responses = []
66
  for r in WEBS_instance.videos(
67
  keywords,
@@ -82,7 +67,7 @@ def WEBScout2_images():
82
  return jsonify({'error': 'Keywords parameter missing'})
83
 
84
  keywords = params['keywords']
85
- WEBS_instance = WEBS() # Instantiate WEBS without context manager
86
  responses = []
87
  for r in WEBS_instance.images(
88
  keywords,
@@ -102,9 +87,8 @@ def WEBScout_news():
102
  params = request.args
103
  if 'keywords' not in params:
104
  return jsonify({'error': 'Keywords parameter missing'})
105
-
106
  keywords = params['keywords']
107
- WEBS_instance = WEBS() # Instantiate WEBS without context manager
108
  responses = []
109
  for r in WEBS_instance.news(
110
  keywords,
@@ -118,14 +102,14 @@ def WEBScout_news():
118
 
119
  @app.route('/int', methods=['GET'])
120
  def WEBScout3_search():
121
- query = request.args.get('q') # Change 'query' to 'q'
122
  if not query:
123
  return jsonify({'error': 'Query parameter missing'})
124
 
125
- WEBS_instance = WEBS() # Instantiate WEBS without context manager
126
  responses = []
127
  for i, r in enumerate(WEBS_instance.text(query, region='wt-wt', safesearch='off', timelimit='y')):
128
- if i == 10: # Limiting the results to 10
129
  break
130
  responses.append(r)
131
  return jsonify(responses)
@@ -135,42 +119,21 @@ def WEBScout_translate():
135
  params = request.args
136
  if 'keywords' not in params or 'to' not in params:
137
  return jsonify({'error': 'Keywords or target language parameter missing'})
138
-
139
  keywords = params['keywords']
140
  target_language = params['to']
141
- WEBS_instance = WEBS() # Instantiate WEBS without context manager
142
  translation = WEBS_instance.translate(keywords, to=target_language)
143
  return jsonify(translation)
144
-
145
- # Configure the API key
146
-
147
  @app.route('/chat', methods=['POST'])
148
  def chat_gpt():
149
  user_input = request.json.get('message')
150
  if user_input is None:
151
  return jsonify({'error': 'Message parameter missing'})
152
 
153
- messages = [
154
- {
155
- "role": "system",
156
- "content": "Hello! I'm your virtual assistant. How can I help you?"
157
- },
158
- {
159
- "role": "user",
160
- "content": user_input
161
- }
162
- ]
163
-
164
- response = g4f.ChatCompletion.create(
165
- model="gpt-4-32k-0613",
166
- provider=g4f.Provider.GPTalk,
167
- messages=messages,
168
- stream=True,
169
- )
170
-
171
- ms = "".join([str(message) for message in response])
172
- messages.append({"role": "assistant", "content": ms})
173
- return jsonify({"response": ms})
174
 
175
  if __name__ == '__main__':
176
  app.run(debug=True)
 
 
 
1
  from flask import Flask, jsonify, request
2
+ from webscout import WEBS
3
+ from webscout.LLM import LLM
4
+
5
  app = Flask(__name__)
6
 
7
  @app.route('/search', methods=['POST'])
 
11
  return jsonify({'error': 'Query parameter missing'})
12
 
13
  query = data['query']
14
+ limit = data.get('limit', 10) # Default limit to 10 if not provided
15
+ WEBS_instance = WEBS() # Instantiate WEBS without context manager
16
  responses = []
17
  for i, r in enumerate(WEBS_instance.text(query, region='wt-wt', safesearch='off', timelimit='y')):
18
+ if i == limit: # Use the custom limit
19
  break
20
  responses.append(r)
21
  return jsonify(responses)
22
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  @app.route('/mws', methods=['POST'])
24
  def WEBScout_search():
25
  data = request.get_json()
 
27
  return jsonify({'error': 'Query parameter missing'})
28
 
29
  query = data['query']
30
+ WEBS_instance = WEBS() # Instantiate WEBS without context manager
31
  responses = []
32
  for i, r in enumerate(WEBS_instance.text(query, region='wt-wt', safesearch='off', timelimit='y')):
33
+ if i == 2: # Limiting the results to 2
34
  break
35
  responses.append(r)
36
  return jsonify(responses)
37
+
38
  @app.route('/health', methods=['GET'])
39
  def health_check():
40
  return jsonify({'status': 'ok'})
 
46
  return jsonify({'error': 'Keywords parameter missing'})
47
 
48
  keywords = params['keywords']
49
+ WEBS_instance = WEBS() # Instantiate WEBS without context manager
50
  responses = []
51
  for r in WEBS_instance.videos(
52
  keywords,
 
67
  return jsonify({'error': 'Keywords parameter missing'})
68
 
69
  keywords = params['keywords']
70
+ WEBS_instance = WEBS() # Instantiate WEBS without context manager
71
  responses = []
72
  for r in WEBS_instance.images(
73
  keywords,
 
87
  params = request.args
88
  if 'keywords' not in params:
89
  return jsonify({'error': 'Keywords parameter missing'})
 
90
  keywords = params['keywords']
91
+ WEBS_instance = WEBS() # Instantiate WEBS without context manager
92
  responses = []
93
  for r in WEBS_instance.news(
94
  keywords,
 
102
 
103
  @app.route('/int', methods=['GET'])
104
  def WEBScout3_search():
105
+ query = request.args.get('q') # Change 'query' to 'q'
106
  if not query:
107
  return jsonify({'error': 'Query parameter missing'})
108
 
109
+ WEBS_instance = WEBS() # Instantiate WEBS without context manager
110
  responses = []
111
  for i, r in enumerate(WEBS_instance.text(query, region='wt-wt', safesearch='off', timelimit='y')):
112
+ if i == 10: # Limiting the results to 10
113
  break
114
  responses.append(r)
115
  return jsonify(responses)
 
119
  params = request.args
120
  if 'keywords' not in params or 'to' not in params:
121
  return jsonify({'error': 'Keywords or target language parameter missing'})
 
122
  keywords = params['keywords']
123
  target_language = params['to']
124
+ WEBS_instance = WEBS() # Instantiate WEBS without context manager
125
  translation = WEBS_instance.translate(keywords, to=target_language)
126
  return jsonify(translation)
127
+
 
 
128
  @app.route('/chat', methods=['POST'])
129
  def chat_gpt():
130
  user_input = request.json.get('message')
131
  if user_input is None:
132
  return jsonify({'error': 'Message parameter missing'})
133
 
134
+ llm = LLM("mistralai/Mistral-7B-Instruct-v0.1") # Initialize the LLM class with a model
135
+ response = llm.mistral_chat([{"role": "user", "content": user_input}]) # Call the mistral_chat method
136
+ return jsonify({"response": response})
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
137
 
138
  if __name__ == '__main__':
139
  app.run(debug=True)