Spaces:
Sleeping
Sleeping
| import scratchattach as sa | |
| import os | |
| from flask import Flask, request | |
| import requests | |
| import subprocess | |
| import re | |
| from threading import Thread | |
| def Curl(URL): | |
| curl_command = ['curl', '-X', 'GET', URL] | |
| result = subprocess.run(curl_command, | |
| stdout=subprocess.PIPE, | |
| stderr=subprocess.PIPE, | |
| text=True) | |
| if result.returncode == 0: | |
| return result.stdout | |
| sessionid = os.getenv("ID") | |
| useridname = os.getenv("USR") | |
| # Initialize Scratch session | |
| session = sa.login_by_id(sessionid, username=useridname) | |
| cloud = session.connect_cloud("1185047933") | |
| client = cloud.requests() | |
| # Request 1: Get Groq response (with context retention) | |
| def get_groq_response(user_input): | |
| global chat_history | |
| try: | |
| ai_response = Curl(user_input) | |
| ai_response.replace("<","BTTL") | |
| ai_response.replace(">","BTTR") | |
| return ai_response | |
| except Exception as e: | |
| return f"Error: {str(e)}" | |
| client.start(thread=True) | |
| app = Flask(__name__) | |
| def index(): | |
| return """ | |
| Go to https://scratch.mit.edu/projects/1185047933/ for a live demo of this program. | |
| """ |