Spaces:
Sleeping
Sleeping
switch to local api
Browse files
app.py
CHANGED
|
@@ -2,6 +2,7 @@ from flask import Flask, request, Response, jsonify
|
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
from flask_cors import CORS
|
| 4 |
import json
|
|
|
|
| 5 |
|
| 6 |
client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
|
| 7 |
|
|
@@ -34,9 +35,23 @@ def split_text(text):
|
|
| 34 |
result.append(current_chunk.strip())
|
| 35 |
return result
|
| 36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
def generate(
|
| 38 |
prompt, history=[], temperature=0, max_new_tokens=2000, top_p=0.95, repetition_penalty=1.0,
|
| 39 |
):
|
|
|
|
| 40 |
temperature = float(temperature)
|
| 41 |
if temperature < 1e-2:
|
| 42 |
temperature = 1e-2
|
|
|
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
from flask_cors import CORS
|
| 4 |
import json
|
| 5 |
+
import requests
|
| 6 |
|
| 7 |
client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
|
| 8 |
|
|
|
|
| 35 |
result.append(current_chunk.strip())
|
| 36 |
return result
|
| 37 |
|
| 38 |
+
def call_api(prompt_text):
|
| 39 |
+
url = "https://muryshev-mixtral-api-local.hf.space/completion"
|
| 40 |
+
payload = {"prompt": prompt_text}
|
| 41 |
+
|
| 42 |
+
try:
|
| 43 |
+
response = requests.post(url, json=payload)
|
| 44 |
+
response.raise_for_status() # Raise an exception for 4xx or 5xx status codes
|
| 45 |
+
result = response.text # Extract the text result from the JSON response
|
| 46 |
+
return result
|
| 47 |
+
except requests.exceptions.RequestException as e:
|
| 48 |
+
print("Error:", e)
|
| 49 |
+
return None
|
| 50 |
+
|
| 51 |
def generate(
|
| 52 |
prompt, history=[], temperature=0, max_new_tokens=2000, top_p=0.95, repetition_penalty=1.0,
|
| 53 |
):
|
| 54 |
+
return call_api(prompt)
|
| 55 |
temperature = float(temperature)
|
| 56 |
if temperature < 1e-2:
|
| 57 |
temperature = 1e-2
|