Erfan11 commited on
Commit
accfebc
1 Parent(s): dd3e152

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -15
app.py CHANGED
@@ -1,30 +1,25 @@
 
 
1
  import os
2
  from dotenv import load_dotenv
3
- from flask import Flask, request, jsonify
4
- import requests
5
 
6
  load_dotenv()
7
  api_key = os.getenv('HF_API_KEY')
8
  model_path = os.getenv('MODEL_PATH')
9
 
10
- app = Flask(__name__)
11
-
12
  def get_model_predictions(text):
13
  headers = {"Authorization": f"Bearer {api_key}"}
14
  payload = {"inputs": text}
15
  response = requests.post(f"https://api.huggingface.co/models/{model_path}", headers=headers, json=payload)
16
  return response.json()
17
 
18
- @app.route('/predict', methods=['POST'])
19
- def predict():
20
- data = request.get_json()
21
- text = data['text']
22
- prediction = get_model_predictions(text)
23
- return jsonify(prediction)
24
 
25
- @app.route('/', methods=['GET'])
26
- def index():
27
- return "Welcome to My AI!"
28
 
29
- if __name__ == '__main__':
30
- app.run(debug=True)
 
 
 
 
 
1
+ import streamlit as st
2
+ import requests
3
  import os
4
  from dotenv import load_dotenv
 
 
5
 
6
  load_dotenv()
7
  api_key = os.getenv('HF_API_KEY')
8
  model_path = os.getenv('MODEL_PATH')
9
 
 
 
10
  def get_model_predictions(text):
11
  headers = {"Authorization": f"Bearer {api_key}"}
12
  payload = {"inputs": text}
13
  response = requests.post(f"https://api.huggingface.co/models/{model_path}", headers=headers, json=payload)
14
  return response.json()
15
 
16
+ st.title("My AI Prediction App")
 
 
 
 
 
17
 
18
+ text = st.text_area("Enter text to predict")
 
 
19
 
20
+ if st.button("Predict"):
21
+ if text:
22
+ result = get_model_predictions(text)
23
+ st.write("Prediction:", result)
24
+ else:
25
+ st.write("Please enter some text.")