Spaces:
Paused
Paused
| 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 | |
| app = Flask(__name__) | |
| # Tracking API usage | |
| 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) | |
| 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) | |
| 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) | |
| def Web(): | |
| key = request.args.get('prompt', '') | |
| result = { | |
| 'response': Online_Scraper(key) | |
| } | |
| return jsonify(result) | |
| def IMGEN(): | |
| data = request.json | |
| prompt = data.get('prompt', '') | |
| key = data.get('key', '') | |
| API_URL = "https://api-inference.huggingface.co/models/OEvortex/HelpingAI-PixelCraft" | |
| headers = {"Authorization": f"Bearer {key}"} | |
| result = { | |
| 'response': requests.post(API_URL, headers=headers, json={"inputs": prompt,}).content | |
| } | |
| return jsonify(result) | |
| def get_counters(): | |
| return jsonify(counter),jsonify({"data":str(listdir(r"static/data/"))}) | |
| if __name__ == '__main__': | |
| app.run() | |