Create application.py
Browse files- application.py +47 -0
application.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pyChatGPT import ChatGPT
|
| 2 |
+
import os
|
| 3 |
+
# os.environ["SessionToken"] = SessionToken
|
| 4 |
+
# refresh the authorization token
|
| 5 |
+
session_token = os.environ.get('SessionToken')
|
| 6 |
+
|
| 7 |
+
def chat_hf(text,session_tokenz):
|
| 8 |
+
|
| 9 |
+
try:
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
api = ChatGPT(session_token)
|
| 13 |
+
resp = api.send_message(text)
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
api.refresh_auth() # refresh the authorization token
|
| 17 |
+
api.reset_conversation() # reset the conversation
|
| 18 |
+
xyz = resp['message']
|
| 19 |
+
except:
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
api = ChatGPT(session_tokenz)
|
| 23 |
+
resp = api.send_message(text)
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
api.refresh_auth() # refresh the authorization token
|
| 27 |
+
api.reset_conversation() # reset the conversation
|
| 28 |
+
xyz = resp['message']
|
| 29 |
+
|
| 30 |
+
return xyz
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
#@title GRadio for SDK api
|
| 36 |
+
|
| 37 |
+
import gradio as gr
|
| 38 |
+
gr.Interface(
|
| 39 |
+
chat_hf,
|
| 40 |
+
[gr.Textbox(label = ' Input custom text for ChatGPT! '),
|
| 41 |
+
gr.Textbox(label = ' If it fails enter custom session key ')],
|
| 42 |
+
outputs = gr.outputs.Textbox(type="text",label="chatGPT response"),
|
| 43 |
+
examples =[['Write poem on crypto','xyz'],['Write a sales pitch for social media app','xyz'],['Reverse string in python','xyz'] ]
|
| 44 |
+
, title = "" +' ChatGpt 🤖💬💻 on 🤗 huggingface. '+ "",
|
| 45 |
+
description="""ChatGPT 🤖💬💻 is a conversational AI app that allows users to engage in natural language conversations with a virtual assistant. The app uses advanced machine learning algorithms to understand and respond to user queries in a human-like manner. With its ability to answer follow-up questions, admit mistakes, and reject inappropriate requests, ChatGPT offers a highly interactive and engaging experience. Try ChatGPT now and experience the power of language modeling in dialogue built with ❤️ @[Xhaheen](https://www.linkedin.com/in/sallu-mandya/) \n\nIf it fails enter cusom session key see video for reference refer @[Bhavesh bhat video](https://youtu.be/TdNSj_qgdFk)
|
| 46 |
+
<p>You can duplicating this space and use your own session token: <a style='display:inline-block' href='https://huggingface.co/spaces/Xhaheen/ChatGPT_HF?duplicate=true'><img src='https://img.shields.io/badge/-Duplicate%20Space-blue?labelColor=white&style=flat&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAP5JREFUOE+lk7FqAkEURY+ltunEgFXS2sZGIbXfEPdLlnxJyDdYB62sbbUKpLbVNhyYFzbrrA74YJlh9r079973psed0cvUD4A+4HoCjsA85X0Dfn/RBLBgBDxnQPfAEJgBY+A9gALA4tcbamSzS4xq4FOQAJgCDwV2CPKV8tZAJcAjMMkUe1vX+U+SMhfAJEHasQIWmXNN3abzDwHUrgcRGmYcgKe0bxrblHEB4E/pndMazNpSZGcsZdBlYJcEL9Afo75molJyM2FxmPgmgPqlWNLGfwZGG6UiyEvLzHYDmoPkDDiNm9JR9uboiONcBXrpY1qmgs21x1QwyZcpvxt9NS09PlsPAAAAAElFTkSuQmCC&logoWidth=14' alt='Duplicate Space'></a></p>
|
| 47 |
+
""").launch(debug = True)
|