Spaces:
DIVY118
/
Runtime error

File size: 5,655 Bytes
ad89eb2
 
 
 
 
 
 
27c7f8a
234eddc
4ef8a32
747f20e
 
ad89eb2
 
5f8f486
ad89eb2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
abac9ba
27c7f8a
abac9ba
 
 
 
27c7f8a
5ee100a
27c7f8a
 
 
dc3b37b
4ef8a32
 
 
0ef26c5
 
 
cc0da15
 
 
 
0ef26c5
 
 
cc0da15
0ef26c5
cc0da15
 
 
0ef26c5
cc0da15
 
 
0ef26c5
cc0da15
 
 
0ef26c5
cc0da15
 
0ef26c5
 
 
 
 
 
b5385c0
0ef26c5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cc0da15
0ef26c5
cc0da15
0ef26c5
 
 
b5385c0
ad89eb2
234eddc
4e72cef
234eddc
9ab660c
234eddc
 
f472d71
234eddc
 
5fb868a
234eddc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ad89eb2
 
 
 
 
 
9c44c09
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
from flask import Flask, request, jsonify
from mistral import Mistral7B
from gpt import ChatGpt
from news import News
from datetime import datetime
from os import listdir
from web import Online_Scraper
import requests
from RT import RealTimeGemini
from time import time as t
import os

app = Flask(__name__)

 

@app.route('/mistral7b', methods=['POST'])
def generate():
    # Get data from the request
    data = request.json
    prompt = data.get('prompt', '')
    messages = data.get('messages', [])
    key = data.get('key', '')
    
    # Call Mistral7B function
    response, updated_messages, execution_time = Mistral7B(prompt, messages,key)

    # Prepare the response
    result = {
        'response': response,
        'messages': updated_messages,
        'execution_time': execution_time
    }
    return jsonify(result)

@app.route('/chatgpt', methods=['POST'])
def chat():
    # Get data from the request
    data = request.json
    user_message = data.get('message', '')
    messages = data.get('messages', [])

    # Call ChatGpt function
    response, updated_messages, execution_time = ChatGpt(user_message, messages)

    # Prepare the response
    result = {
        'response': response,
        'messages': updated_messages,
        'execution_time': execution_time
    }
    return jsonify(result)

@app.route('/news', methods=['GET'])
def get_news():
    # Get data from the request
    key = request.args.get('key', '')
    cache_flag = request.args.get('cache', 'True').lower() == 'true'

    # Call News function
    news, error, execution_time = News(key, cache_flag)

    # Prepare the response
    result = {
        'news': news,
        'error': error,
        'execution_time': execution_time
    }
    return jsonify(result)

@app.route('/web', methods=['GET'])
def Web():
    key = request.args.get('prompt', '')
    result = {
        'response': Online_Scraper(key)
    }
    return jsonify(result)

@app.route('/imageneration', methods=['POST'])
def IMGEN():
    data = request.json
    prompt = data.get('prompt', '')
    key = data.get('key', '')

    
    API_URL = "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-2-1"
    headers = {"Authorization": f"Bearer {key}"}


    return requests.post(API_URL, headers=headers, json={"inputs": prompt,}).content

@app.route('/generativeai', methods=['POST'])
def Genration():
    try:
        import google.generativeai as genai
        generation_config = {
            "temperature": 0.7,
            "top_p": 1,
            "top_k": 1,
            "max_output_tokens": 300,
        }
        
        safety_settings = [
            {
            "category": "HARM_CATEGORY_HARASSMENT",
            "threshold": "BLOCK_NONE"
            },
            {
            "category": "HARM_CATEGORY_HATE_SPEECH",
            "threshold": "BLOCK_NONE"
            },
            {
            "category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
            "threshold": "BLOCK_NONE"
            },
            {
            "category": "HARM_CATEGORY_DANGEROUS_CONTENT",
            "threshold": "BLOCK_NONE"
            },
        ]
        
        model = genai.GenerativeModel(
         model_name="gemini-pro",
         generation_config=generation_config,
         safety_settings=safety_settings)
    
        data = request.json
        messages = data.get('messages', [])
        key = data.get('key', '')
        
        C=t()
        genai.configure(api_key=key)
        response = model.generate_content(messages)
        
        
        # Prepare the response
        result = {
            'response': response.text,
            'execution_time': t()-C
        }
        return jsonify(result)
    except Exception as e:
        result = {
            'response': f"{e}",
            'execution_time': t()-C
        }
        return jsonify(result)


@app.route('/realtime', methods=['POST'])
def GenrationRT():
    try:
        
        import google.generativeai as genai
        generation_config = {
            "temperature": 0.9,
            "top_p": 1,
            "top_k": 1,
            "max_output_tokens": 2048,
        }
        
        safety_settings = [
            {
            "category": "HARM_CATEGORY_HARASSMENT",
            "threshold": "BLOCK_NONE"
            },
            {
            "category": "HARM_CATEGORY_HATE_SPEECH",
            "threshold": "BLOCK_NONE"
            },
            {
            "category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
            "threshold": "BLOCK_NONE"
            },
            {
            "category": "HARM_CATEGORY_DANGEROUS_CONTENT",
            "threshold": "BLOCK_NONE"
            },
        ]
        
        model = genai.GenerativeModel(
         model_name="gemini-pro",
         generation_config=generation_config,
         safety_settings=safety_settings)
    
        data = request.json
        query = data.get('prompt', "hello ?")
        messages = data.get('messages', [])
        key = data.get('key', '')
        
        C=t()
        genai.configure(api_key=key)
        response = RealTimeGemini(query,messages,model)
        
        
        # Prepare the response
        result = {
            'response': response,
            'execution_time': t()-C
        }
        return jsonify(result)
    except Exception as e:
        result = {
            'response': f"{e}",
            'execution_time': t()-C
        }
        return jsonify(result)


@app.route('/divyanshpizza', methods=['GET'])
def get_counters():
    return jsonify(counter),jsonify({"data":str(listdir(r"static/data/"))})


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