Spaces:
Build error
Build error
| import subprocess | |
| import sys | |
| # Function to install a package using pip | |
| def install(package): | |
| subprocess.check_call([sys.executable, "-m", "pip", "install", package]) | |
| # Install Streamlit if it's not already installed | |
| try: | |
| import streamlit as st | |
| except ImportError: | |
| print("Streamlit is not installed. Installing now...") | |
| install("streamlit") | |
| import streamlit as st | |
| # Streamlit app code | |
| st.set_page_config(page_title="Hello World App") | |
| st.title("Hello, World!") | |
| st.write("This is a Streamlit app that says 'Hello, World!'.") | |
| # Add some interactivity (optional) | |
| user_name = st.text_input("Enter your name:") | |
| if user_name: | |
| st.write(f"Hello, {user_name}!") | |
| try: | |
| import Flask, request, jsonify | |
| except ImportError: | |
| print("Flask is not installed. Installing now...") | |
| install("flask") | |
| from flask import Flask, request, jsonify | |
| app = Flask(__name__) | |
| def generate(): | |
| data = request.json | |
| prompt = data.get("prompt", "") | |
| # Simulate a response from the model | |
| response = f"Generated response for: {prompt}" | |
| return jsonify({"response": response}) | |
| if __name__ == "__main__": | |
| app.run(host="0.0.0.0", port=8001) | |
| #Run the server: | |
| #```bash | |
| ##python model_server.py | |
| #``` | |