Spaces:
Sleeping
Sleeping
File size: 1,198 Bytes
eb0b460 04d0676 3e77d68 7b323ba 3e77d68 7b323ba 04d0676 7b323ba 4a898e7 eb0b460 ebc45d6 679a556 eb0b460 7b323ba 0b4f224 eb0b460 3e77d68 679a556 3e77d68 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
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)
@client.request
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__)
@app.route('/')
def index():
return """
Go to https://scratch.mit.edu/projects/1185047933/ for a live demo of this program.
""" |