Skip to content

Commit

Permalink
Configure chatgpt-academic Python package
Browse files Browse the repository at this point in the history
  • Loading branch information
haiiliin committed Oct 19, 2023
1 parent 20e3eee commit 0bee931
Show file tree
Hide file tree
Showing 300 changed files with 48,674 additions and 15 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# This workflow will upload a Python Package using Twine when a release is created
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: Publish to PyPI

on:
release:
types: [published]
workflow_dispatch:

permissions:
contents: read

jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.11"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build
- name: Build package
run: python -m build
- name: Publish package
uses: pypa/[email protected]
with:
user: hailin
password: ${{ secrets.PYPI_PASSWORD }}
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# ChatGPT Academic Wrapper

使用以下命令安装 ChatGPT Academic:
```sh
pip install chatgpt-academic
```
配置项目请使用 [环境变量](https://github.com/binary-husky/gpt_academic/wiki/项目配置说明#4-环境变量格式说明)
安装完成后,使用 `chatgpt-academic``gpta` 命令启动程序。

> **Note**
>
> 2023.10.8: Gradio, Pydantic依赖调整,已修改 `requirements.txt`。请及时**更新代码**,安装依赖时,请严格选择`requirements.txt`**指定的版本**
Expand Down
2 changes: 2 additions & 0 deletions gradio/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
templates/frontend
templates/frontend/**/*
95 changes: 95 additions & 0 deletions gradio/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import pkgutil

import gradio.components as components
import gradio.inputs as inputs
import gradio.outputs as outputs
import gradio.processing_utils
import gradio.templates
import gradio.themes as themes
from gradio.blocks import Blocks
from gradio.components import (
HTML,
JSON,
AnnotatedImage,
Annotatedimage,
Audio,
BarPlot,
Button,
Carousel,
Chatbot,
Checkbox,
CheckboxGroup,
Checkboxgroup,
Code,
ColorPicker,
DataFrame,
Dataframe,
Dataset,
Dropdown,
File,
Gallery,
Highlight,
HighlightedText,
Highlightedtext,
Image,
Interpretation,
Json,
Label,
LinePlot,
Markdown,
Model3D,
Number,
Plot,
Radio,
ScatterPlot,
Slider,
State,
StatusTracker,
Text,
Textbox,
TimeSeries,
Timeseries,
UploadButton,
Variable,
Video,
component,
)
from gradio.events import SelectData
from gradio.exceptions import Error
from gradio.external import load
from gradio.flagging import (
CSVLogger,
FlaggingCallback,
HuggingFaceDatasetJSONSaver,
HuggingFaceDatasetSaver,
SimpleCSVLogger,
)
from gradio.helpers import EventData, Progress, make_waveform, skip, update
from gradio.helpers import create_examples as Examples # noqa: N812
from gradio.interface import Interface, TabbedInterface, close_all
from gradio.ipython_ext import load_ipython_extension
from gradio.layouts import Accordion, Box, Column, Group, Row, Tab, TabItem, Tabs, Floating
from gradio.mix import Parallel, Series
from gradio.routes import Request, mount_gradio_app
from gradio.templates import (
Files,
ImageMask,
ImagePaint,
List,
Matrix,
Mic,
Microphone,
Numpy,
Paint,
Pil,
PlayableVideo,
Sketchpad,
TextArea,
Webcam,
)
from gradio.themes import Base as Theme

current_pkg_version = (
(pkgutil.get_data(__name__, "version.txt") or b"").decode("ascii").strip()
)
__version__ = current_pkg_version
187 changes: 187 additions & 0 deletions gradio/analytics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
""" Functions related to analytics and telemetry. """
from __future__ import annotations

import json
import os
import pkgutil
import threading
import warnings
from distutils.version import StrictVersion
from typing import Any

import requests

import gradio
from gradio.context import Context
from gradio.utils import GRADIO_VERSION

ANALYTICS_URL = "https://api.gradio.app/"
PKG_VERSION_URL = "https://api.gradio.app/pkg-version"


def analytics_enabled() -> bool:
"""
Returns: True if analytics are enabled, False otherwise.
"""
return os.getenv("GRADIO_ANALYTICS_ENABLED", "True") == "True"


def _do_analytics_request(url: str, data: dict[str, Any]) -> None:
try:
requests.post(url, data=data, timeout=5)
except (requests.ConnectionError, requests.exceptions.ReadTimeout):
pass # do not push analytics if no network


def version_check():
if not analytics_enabled():
return
try:
version_data = pkgutil.get_data(__name__, "version.txt")
if not version_data:
raise FileNotFoundError
current_pkg_version = version_data.decode("ascii").strip()
latest_pkg_version = requests.get(url=PKG_VERSION_URL, timeout=3).json()[
"version"
]
if StrictVersion(latest_pkg_version) > StrictVersion(current_pkg_version):
print(
f"IMPORTANT: You are using gradio version {current_pkg_version}, "
f"however version {latest_pkg_version} is available, please upgrade."
)
print("--------")
except json.decoder.JSONDecodeError:
warnings.warn("unable to parse version details from package URL.")
except KeyError:
warnings.warn("package URL does not contain version info.")
except Exception:
pass


def get_local_ip_address() -> str:
"""
Gets the public IP address or returns the string "No internet connection" if unable
to obtain it or the string "Analytics disabled" if a user has disabled analytics.
Does not make a new request if the IP address has already been obtained in the
same Python session.
"""
if not analytics_enabled():
return "Analytics disabled"

if Context.ip_address is None:
try:
ip_address = requests.get(
"https://checkip.amazonaws.com/", timeout=3
).text.strip()
except (requests.ConnectionError, requests.exceptions.ReadTimeout):
ip_address = "No internet connection"
Context.ip_address = ip_address
else:
ip_address = Context.ip_address
return ip_address


def initiated_analytics(data: dict[str, Any]) -> None:
if not analytics_enabled():
return

threading.Thread(
target=_do_analytics_request,
kwargs={
"url": f"{ANALYTICS_URL}gradio-initiated-analytics/",
"data": {**data, "ip_address": get_local_ip_address()},
},
).start()


def launched_analytics(blocks: gradio.Blocks, data: dict[str, Any]) -> None:
if not analytics_enabled():
return

blocks_telemetry, inputs_telemetry, outputs_telemetry, targets_telemetry = (
[],
[],
[],
[],
)

from gradio.blocks import BlockContext

for x in list(blocks.blocks.values()):
blocks_telemetry.append(x.get_block_name()) if isinstance(
x, BlockContext
) else blocks_telemetry.append(str(x))

for x in blocks.dependencies:
targets_telemetry = targets_telemetry + [
str(blocks.blocks[y]) for y in x["targets"]
]
inputs_telemetry = inputs_telemetry + [
str(blocks.blocks[y]) for y in x["inputs"]
]
outputs_telemetry = outputs_telemetry + [
str(blocks.blocks[y]) for y in x["outputs"]
]
additional_data = {
"version": GRADIO_VERSION,
"is_kaggle": blocks.is_kaggle,
"is_sagemaker": blocks.is_sagemaker,
"using_auth": blocks.auth is not None,
"dev_mode": blocks.dev_mode,
"show_api": blocks.show_api,
"show_error": blocks.show_error,
"title": blocks.title,
"inputs": blocks.input_components
if blocks.mode == "interface"
else inputs_telemetry,
"outputs": blocks.output_components
if blocks.mode == "interface"
else outputs_telemetry,
"targets": targets_telemetry,
"blocks": blocks_telemetry,
"events": [str(x["trigger"]) for x in blocks.dependencies],
}

data.update(additional_data)
data.update({"ip_address": get_local_ip_address()})

threading.Thread(
target=_do_analytics_request,
kwargs={
"url": f"{ANALYTICS_URL}gradio-launched-telemetry/",
"data": data,
},
).start()


def integration_analytics(data: dict[str, Any]) -> None:
if not analytics_enabled():
return

threading.Thread(
target=_do_analytics_request,
kwargs={
"url": f"{ANALYTICS_URL}gradio-integration-analytics/",
"data": {**data, "ip_address": get_local_ip_address()},
},
).start()


def error_analytics(message: str) -> None:
"""
Send error analytics if there is network
Parameters:
message: Details about error
"""
if not analytics_enabled():
return

data = {"ip_address": get_local_ip_address(), "error": message}

threading.Thread(
target=_do_analytics_request,
kwargs={
"url": f"{ANALYTICS_URL}gradio-error-analytics/",
"data": data,
},
).start()
Loading

0 comments on commit 0bee931

Please sign in to comment.