File size: 6,144 Bytes
a143120
2f42528
a143120
9a51fc1
a143120
 
 
324ca83
a143120
 
324ca83
a143120
 
324ca83
 
 
 
 
 
 
2480bb0
5cc9742
a61eaba
5cc9742
 
 
a143120
5cc9742
 
 
 
3d9cffd
5cc9742
 
 
2480bb0
a143120
 
 
324ca83
a143120
324ca83
a143120
 
324ca83
a143120
 
324ca83
 
 
 
 
 
 
 
 
 
 
 
 
a143120
 
324ca83
a143120
 
324ca83
a143120
 
324ca83
 
 
 
 
 
 
 
 
 
 
 
 
 
a143120
 
324ca83
a143120
 
324ca83
a143120
 
324ca83
 
 
 
 
 
 
 
 
 
 
a143120
 
324ca83
34d1da7
a143120
324ca83
 
 
 
 
9ade9a3
324ca83
 
a143120
 
 
324ca83
a143120
 
324ca83
a143120
 
 
324ca83
 
 
390d552
 
 
a143120
 
390d552
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a143120
 
324ca83
 
a143120
 
 
 
 
324ca83
 
 
 
a143120
 
 
 
66d850b
 
a143120
 
 
 
324ca83
a143120
 
 
324ca83
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
import g4f
from webscout import WEBS
from flask import Flask, jsonify, request
import google.generativeai as palm
app = Flask(__name__)

@app.route('/search', methods=['POST'])
def WEBScout2_search():
    data = request.get_json()
    if 'query' not in data:
        return jsonify({'error': 'Query parameter missing'})

    query = data['query']
    WEBS_instance = WEBS()  # Instantiate WEBS without context manager
    responses = []
    for i, r in enumerate(WEBS_instance.text(query, region='wt-wt', safesearch='off', timelimit='y')):
        if i ==   10:  # Limiting the results to   10
            break
        responses.append(r)
    return jsonify(responses)
    
@app.route('/mws', methods=['POST'])
def WEBScout_search():
    data = request.get_json()
    if 'query' not in data:
        return jsonify({'error': 'Query parameter missing'})

    query = data['query']
    WEBS_instance = WEBS()  # Instantiate WEBS without context manager
    responses = []
    for i, r in enumerate(WEBS_instance.text(query, region='wt-wt', safesearch='off', timelimit='y')):
        if i ==   2:  # Limiting the results to   10
            break
        responses.append(r)
    return jsonify(responses)
    
@app.route('/health', methods=['GET'])
def health_check():
    return jsonify({'status': 'ok'})

@app.route('/video', methods=['GET'])
def WEBScout_videos():
    params = request.args
    if 'keywords' not in params:
        return jsonify({'error': 'Keywords parameter missing'})

    keywords = params['keywords']
    WEBS_instance = WEBS()  # Instantiate WEBS without context manager
    responses = []
    for r in WEBS_instance.videos(
        keywords,
        region="wt-wt",
        safesearch="off",
        timelimit="w",
        resolution="high",
        duration="medium",
        max_results=10,
    ):
        responses.append(r)
    return jsonify(responses)

@app.route('/img', methods=['GET'])
def WEBScout2_images():
    params = request.args
    if 'keywords' not in params:
        return jsonify({'error': 'Keywords parameter missing'})

    keywords = params['keywords']
    WEBS_instance = WEBS()  # Instantiate WEBS without context manager
    responses = []
    for r in WEBS_instance.images(
        keywords,
        region="wt-wt",
        safesearch="off",
        size=None,
        type_image=None,
        layout=None,
        license_image=None,
        max_results=10,
    ):
        responses.append(r)
    return jsonify(responses)

@app.route('/news', methods=['GET'])
def WEBScout_news():
    params = request.args
    if 'keywords' not in params:
        return jsonify({'error': 'Keywords parameter missing'})

    keywords = params['keywords']
    WEBS_instance = WEBS()  # Instantiate WEBS without context manager
    responses = []
    for r in WEBS_instance.news(
        keywords,
        region="wt-wt",
        safesearch="off",
        timelimit="m",
        max_results=10
    ):
        responses.append(r)
    return jsonify(responses)

@app.route('/int', methods=['GET'])
def WEBScout3_search():
    query = request.args.get('q')  # Change 'query' to 'q'
    if not query:
        return jsonify({'error': 'Query parameter missing'})

    WEBS_instance = WEBS()  # Instantiate WEBS without context manager
    responses = []
    for i, r in enumerate(WEBS_instance.text(query, region='wt-wt', safesearch='off', timelimit='y')):
        if i ==  10:  # Limiting the results to  10
            break
        responses.append(r)
    return jsonify(responses)

@app.route('/translate', methods=['GET'])
def WEBScout_translate():
    params = request.args
    if 'keywords' not in params or 'to' not in params:
        return jsonify({'error': 'Keywords or target language parameter missing'})

    keywords = params['keywords']
    target_language = params['to']
    WEBS_instance = WEBS()  # Instantiate WEBS without context manager
    translation = WEBS_instance.translate(keywords, to=target_language)
    return jsonify(translation)
    
# Configure the API key
palm.configure(api_key="AIzaSyDmHbZlWJJBlaW5BAJwfOu7HP-JAKFiCpY")

@app.route('/chat', methods=['POST'])
def generate():
    data = request.get_json()
    model = data.get('model', 'models/text-bison-001')
    temperature = data.get('temperature', 1)
    candidate_count = data.get('candidate_count', 1)
    top_k = data.get('top_k', 40)
    top_p = data.get('top_p', 0.95)
    max_output_tokens = data.get('max_output_tokens', 1024)
    stop_sequences = data.get('stop_sequences', [])
    safety_settings = data.get('safety_settings', [
        {"category": "HARM_CATEGORY_DEROGATORY", "threshold": "BLOCK_NONE"},
        {"category": "HARM_CATEGORY_TOXICITY", "threshold": "BLOCK_NONE"},
        {"category": "HARM_CATEGORY_VIOLENCE", "threshold": "BLOCK_NONE"},
        {"category": "HARM_CATEGORY_SEXUAL", "threshold": "BLOCK_NONE"},
        {"category": "HARM_CATEGORY_MEDICAL", "threshold": "BLOCK_NONE"},
        {"category": "HARM_CATEGORY_DANGEROUS", "threshold": "BLOCK_NONE"},
    ])

    result = palm.generate(
        model=model,
        temperature=temperature,
        candidate_count=candidate_count,
        top_k=top_k,
        top_p=top_p,
        max_output_tokens=max_output_tokens,
        stop_sequences=stop_sequences,
        safety_settings=safety_settings
    )

    return jsonify(result)
    
@app.route('/gpt', methods=['POST'])
def chat_gpt():
    user_input = request.json.get('message')
    if user_input is None:
        return jsonify({'error': 'Message parameter missing'})

    messages = [
        {
            "role": "system",
            "content": "Hello! I'm your virtual assistant. How can I help you?"
        },
        {
            "role": "user",
            "content": user_input
        }
    ]

    response = g4f.ChatCompletion.create(
        model="gpt-4-32k-0613",
        provider=g4f.Provider.GPTalk,
        messages=messages,
        stream=True,
    )

    ms = "".join([str(message) for message in response])
    messages.append({"role": "assistant", "content": ms})
    return jsonify({"response": ms})

if __name__ == '__main__':
    app.run(debug=True)