{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "tags": [] }, "outputs": [], "source": [ "import requests\n", "import json\n", "from urllib.request import urlretrieve\n", "import pandas as pd" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import anvil.server\n", "anvil.server.connect('PLMOIU5VCGGUOJH2XORIBWV3-ZXZVFLWX7QFIIAF4')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "anvil.server.call('encode_anvil','I am a robot')[0]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def encode(text,server='local'):\n", " headers = {'Content-Type': 'application/json'}\n", " if server=='local': url='http://127.0.0.1:7860/encode'\n", " elif server=='hf': url='https://huggingface.co/spaces/gmshroff/gmserver/encode'\n", " body={'text':text}\n", " response=requests.post(url=url,data=json.dumps(body),headers = {'Content-Type': 'application/json'})\n", " return response\n", " return json.loads(response.content)['embedding']" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "response=encode('I am a robot',server='local')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "response.content" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "headers = {'Content-Type': 'application/json'}\n", "# url='http://127.0.0.1:5000/run'\n", "url='https://huggingface.co/spaces/gmshroff/gmserver/'\n", "# url='http://127.0.0.1:7860/run'\n", "# body={\"script\":\"python update_valdata.py\"}\n", "# body={\"script\":\"pwd\"}" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "response=requests.get(url=url)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "response.content" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# url='http://127.0.0.1:7860/encode'\n", "body={'text':'I am very good'}\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "response=requests.post(url=url,data=json.dumps(body),headers = {'Content-Type': 'application/json'})\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "url" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(response)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(response.__dict__)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(json.loads(response.content)['embedding'])" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [] }, "outputs": [], "source": [ "urlretrieve(url='http://127.0.0.1:7860/file/data.csv',filename='./returned_file.csv')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "df=pd.read_parquet('/tmp/validation_subset_int8.parquet')" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.13" } }, "nbformat": 4, "nbformat_minor": 4 }