Spaces:
Sleeping
Sleeping
Update app.py
#2
by
falethera - opened
app.py
CHANGED
|
@@ -1,52 +1,12 @@
|
|
| 1 |
-
import openai
|
| 2 |
import gradio as gr
|
| 3 |
-
import
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
with open('conversation.json', 'r') as f:
|
| 14 |
-
return json.load(f)
|
| 15 |
-
except FileNotFoundError:
|
| 16 |
-
return []
|
| 17 |
-
|
| 18 |
-
messages = load_conversation()
|
| 19 |
-
|
| 20 |
-
if not messages:
|
| 21 |
-
messages.append({"role": "system", "content": "You are a knowledgeable assistant specialized in recruiting and hiring, and familiar with ADP Workforce Now Recruitment and various hiring and CRM tools."})
|
| 22 |
-
|
| 23 |
-
def CustomChatGPT(user_input):
|
| 24 |
-
messages.append({"role": "user", "content": user_input})
|
| 25 |
-
|
| 26 |
-
# Ensure the conversation fits within the model's maximum token limit
|
| 27 |
-
conversation = messages[-4096:]
|
| 28 |
-
|
| 29 |
-
try:
|
| 30 |
-
response = openai.ChatCompletion.create(
|
| 31 |
-
model="gpt-3.5-turbo",
|
| 32 |
-
messages=conversation,
|
| 33 |
-
max_tokens=1000,
|
| 34 |
-
temperature=0.7)
|
| 35 |
-
except openai.api_resources.request_error.RequestError as e:
|
| 36 |
-
print(f"Received error from OpenAI: {e}")
|
| 37 |
-
return "I'm sorry, but I'm unable to generate a response at this time."
|
| 38 |
-
|
| 39 |
-
ChatGPT_reply = response["choices"][0]["message"]["content"]
|
| 40 |
-
messages.append({"role": "assistant", "content": ChatGPT_reply})
|
| 41 |
-
|
| 42 |
-
save_conversation()
|
| 43 |
-
|
| 44 |
-
return ChatGPT_reply
|
| 45 |
-
|
| 46 |
-
interface = gr.Interface(fn=CustomChatGPT,
|
| 47 |
-
inputs="textbox",
|
| 48 |
-
outputs="textbox",
|
| 49 |
-
title="HR HELPER",
|
| 50 |
-
description="Chat with a specialized assistant that can answer questions about recruiting, hiring, and various HR and CRM tools. Developed by A. Leschik.")
|
| 51 |
-
|
| 52 |
interface.launch()
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from gradio import inputs
|
| 3 |
+
description = "Story generation with GPT-2"
|
| 4 |
+
interface = gr.Interface.load("huggingface/pranavpsv/gpt2-genre-story-generator",
|
| 5 |
+
title = "Story Generation with GPT-2",
|
| 6 |
+
inputs = [
|
| 7 |
+
gr.inputs.Textbox(lines=7, label="Story"),
|
| 8 |
+
],
|
| 9 |
+
description=description,
|
| 10 |
+
examples=[["Adventurer is approached by a mysterious stranger in the tavern for a new quest"]]
|
| 11 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
interface.launch()
|