Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,16 +1,19 @@
|
|
| 1 |
import os
|
| 2 |
from openai import OpenAI
|
| 3 |
-
from flask import Flask, request, jsonify, render_template
|
|
|
|
| 4 |
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
app = Flask(__name__)
|
| 7 |
|
| 8 |
client = OpenAI(
|
| 9 |
base_url="https://router.huggingface.co/v1",
|
| 10 |
-
api_key=os.environ["HF_TOKEN"],
|
| 11 |
)
|
| 12 |
|
| 13 |
-
app = Flask(__name__)
|
| 14 |
@app.route("/")
|
| 15 |
def index():
|
| 16 |
return render_template("index.html")
|
|
@@ -51,7 +54,7 @@ Rules:
|
|
| 51 |
|
| 52 |
try:
|
| 53 |
completion = client.chat.completions.create(
|
| 54 |
-
model="Qwen/
|
| 55 |
messages=[
|
| 56 |
{
|
| 57 |
"role": "system",
|
|
@@ -99,7 +102,7 @@ Rules:
|
|
| 99 |
try:
|
| 100 |
|
| 101 |
completion = client.chat.completions.create(
|
| 102 |
-
model="Qwen/
|
| 103 |
messages=[
|
| 104 |
{
|
| 105 |
"role": "system",
|
|
@@ -149,7 +152,7 @@ Rules:
|
|
| 149 |
try:
|
| 150 |
|
| 151 |
completion = client.chat.completions.create(
|
| 152 |
-
model="Qwen/
|
| 153 |
messages=[
|
| 154 |
{
|
| 155 |
"role": "system",
|
|
@@ -186,7 +189,7 @@ Never mention the underlying AI model.
|
|
| 186 |
|
| 187 |
try:
|
| 188 |
completion = client.chat.completions.create(
|
| 189 |
-
model="Qwen/
|
| 190 |
messages=[
|
| 191 |
{
|
| 192 |
"role": "system",
|
|
@@ -204,8 +207,8 @@ Never mention the underlying AI model.
|
|
| 204 |
return jsonify({"answer": response})
|
| 205 |
except Exception as e:
|
| 206 |
print(f"Error: {e}")
|
| 207 |
-
return jsonify({"error": "An error occurred while processing your request."}), 500
|
| 208 |
|
| 209 |
if __name__ == '__main__':
|
| 210 |
|
| 211 |
-
app.run(host="0.0.0.0", port=7860)
|
|
|
|
| 1 |
import os
|
| 2 |
from openai import OpenAI
|
| 3 |
+
from flask import Flask, request, jsonify, render_template
|
| 4 |
+
import sys
|
| 5 |
|
| 6 |
+
for stream in (sys.stdout, sys.stderr):
|
| 7 |
+
if hasattr(stream, "reconfigure"):
|
| 8 |
+
stream.reconfigure(errors="backslashreplace")
|
| 9 |
|
| 10 |
app = Flask(__name__)
|
| 11 |
|
| 12 |
client = OpenAI(
|
| 13 |
base_url="https://router.huggingface.co/v1",
|
| 14 |
+
api_key="os.environ["HF_TOKEN"]",
|
| 15 |
)
|
| 16 |
|
|
|
|
| 17 |
@app.route("/")
|
| 18 |
def index():
|
| 19 |
return render_template("index.html")
|
|
|
|
| 54 |
|
| 55 |
try:
|
| 56 |
completion = client.chat.completions.create(
|
| 57 |
+
model="Qwen/Qwen3-4B:featherless-ai",
|
| 58 |
messages=[
|
| 59 |
{
|
| 60 |
"role": "system",
|
|
|
|
| 102 |
try:
|
| 103 |
|
| 104 |
completion = client.chat.completions.create(
|
| 105 |
+
model="Qwen/Qwen3-4B:featherless-ai",
|
| 106 |
messages=[
|
| 107 |
{
|
| 108 |
"role": "system",
|
|
|
|
| 152 |
try:
|
| 153 |
|
| 154 |
completion = client.chat.completions.create(
|
| 155 |
+
model="Qwen/Qwen3-4B:featherless-ai",
|
| 156 |
messages=[
|
| 157 |
{
|
| 158 |
"role": "system",
|
|
|
|
| 189 |
|
| 190 |
try:
|
| 191 |
completion = client.chat.completions.create(
|
| 192 |
+
model="Qwen/Qwen3-4B:featherless-ai",
|
| 193 |
messages=[
|
| 194 |
{
|
| 195 |
"role": "system",
|
|
|
|
| 207 |
return jsonify({"answer": response})
|
| 208 |
except Exception as e:
|
| 209 |
print(f"Error: {e}")
|
| 210 |
+
return jsonify({"error": f"An error occurred while processing your request. ERROR: {e}"}), 500
|
| 211 |
|
| 212 |
if __name__ == '__main__':
|
| 213 |
|
| 214 |
+
app.run(host="0.0.0.0", port=7860)
|