Crimson206 commited on
Commit
7ef3e29
Β·
verified Β·
1 Parent(s): 1e7b7d7

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +13 -15
app.py CHANGED
@@ -1,20 +1,18 @@
1
- from langchain.chat_models import ChatOpenAI
2
- from langchain.schema import AIMessage, HumanMessage
3
- import openai
4
  import gradio as gr
5
- import os
6
 
7
- os.environ["OPENAI_API_KEY"] = "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" # Replace with your key
 
 
 
 
8
 
9
- llm = ChatOpenAI(temperature=1.0, model='gpt-3.5-turbo-0613')
 
 
10
 
11
- def predict(message, history):
12
- history_langchain_format = []
13
- for human, ai in history:
14
- history_langchain_format.append(HumanMessage(content=human))
15
- history_langchain_format.append(AIMessage(content=ai))
16
- history_langchain_format.append(HumanMessage(content=message))
17
- gpt_response = llm(history_langchain_format)
18
- return gpt_response.content
19
 
20
- gr.ChatInterface(predict).launch()
 
 
 
 
1
  import gradio as gr
2
+ import time
3
 
4
+ def echo(message, history, system_prompt, tokens):
5
+ response = f"System prompt: {system_prompt}\n Message: {message}."
6
+ for i in range(min(len(response), int(tokens))):
7
+ time.sleep(0.05)
8
+ yield response[: i+1]
9
 
10
+ with gr.Blocks() as demo:
11
+ system_prompt = gr.Textbox("You are helpful AI.", label="System Prompt")
12
+ slider = gr.Slider(10, 100, render=False)
13
 
14
+ gr.ChatInterface(
15
+ echo, additional_inputs=[system_prompt, slider]
16
+ )
 
 
 
 
 
17
 
18
+ demo.launch()