Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
from flask import Flask, request, render_template
|
3 |
+
import requests
|
4 |
+
|
5 |
+
app = Flask(__name__)
|
6 |
+
|
7 |
+
API_URL = "https://api-inference.huggingface.co/models/TinyLlama/TinyLlama-1.1B-Chat-v1.0"
|
8 |
+
api_key = os.environ.get('HUGGING_FACE_API_KEY') # Retrieve API key from environment variable
|
9 |
+
|
10 |
+
def query(payload):
|
11 |
+
headers = {"Authorization": f"Bearer {api_key}"}
|
12 |
+
response = requests.post(API_URL, headers=headers, json=payload)
|
13 |
+
return response.json()
|
14 |
+
|
15 |
+
@app.route('/')
|
16 |
+
def index():
|
17 |
+
return render_template('index.html')
|
18 |
+
|
19 |
+
@app.route('/get_response', methods=['POST'])
|
20 |
+
def get_response():
|
21 |
+
user_input = request.form['user_input']
|
22 |
+
output = query({"inputs": user_input})
|
23 |
+
return output
|
24 |
+
|
25 |
+
if __name__ == '__main__':
|
26 |
+
app.run(debug=True)
|