CosmoAI commited on
Commit
48a29d5
·
1 Parent(s): 0136e49

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -16
app.py CHANGED
@@ -1,3 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  # from dotenv import load_dotenv
2
  # from langchain import HuggingFaceHub, LLMChain
3
  # from langchain import PromptTemplates
@@ -46,27 +80,27 @@
46
  # return simptok(data)
47
 
48
 
49
- from hugchat import hugchat
50
- import gradio as gr
51
- import time
52
 
53
- # Create a chatbot connection
54
- chatbot = hugchat.ChatBot(cookie_path="cookies.json")
55
 
56
- # New a conversation (ignore error)
57
- id = chatbot.new_conversation()
58
- chatbot.change_conversation(id)
59
 
60
 
61
- def get_answer(data):
62
- return chatbot.chat(data)
63
 
64
- gradio_interface = gr.Interface(
65
- fn = get_answer,
66
- inputs = "text",
67
- outputs = "text"
68
- )
69
- gradio_interface.launch()
70
 
71
  # gradio_interface = gradio.Interface(
72
  # fn = responsenew,
 
1
+ import gradio
2
+ from transformers import pipeline
3
+
4
+ # Initialize the Hugging Face model
5
+ model = pipeline(model='google/flan-t5-base')
6
+
7
+
8
+ # Define the chatbot function
9
+ def chatbot(input_text):
10
+ # Generate a response from the Hugging Face model
11
+ response = model(input_text, max_length=50, do_sample=True)[0]['generated_text'].strip()
12
+
13
+ # Return the bot response
14
+ return response
15
+
16
+ # Define the Gradio interface
17
+ gradio_interface = gradio.Interface(
18
+ fn=chatbot,
19
+ inputs='text',
20
+ outputs='text',
21
+ title='Chatbot',
22
+ description='A weird chatbot conversations experience.',
23
+ examples=[
24
+ ['Hi, how are you?']
25
+ ]
26
+ )
27
+
28
+ # Launch the Gradio interface
29
+ gradio_interface.launch()
30
+
31
+
32
+
33
+
34
+
35
  # from dotenv import load_dotenv
36
  # from langchain import HuggingFaceHub, LLMChain
37
  # from langchain import PromptTemplates
 
80
  # return simptok(data)
81
 
82
 
83
+ # from hugchat import hugchat
84
+ # import gradio as gr
85
+ # import time
86
 
87
+ # # Create a chatbot connection
88
+ # chatbot = hugchat.ChatBot(cookie_path="cookies.json")
89
 
90
+ # # New a conversation (ignore error)
91
+ # id = chatbot.new_conversation()
92
+ # chatbot.change_conversation(id)
93
 
94
 
95
+ # def get_answer(data):
96
+ # return chatbot.chat(data)
97
 
98
+ # gradio_interface = gr.Interface(
99
+ # fn = get_answer,
100
+ # inputs = "text",
101
+ # outputs = "text"
102
+ # )
103
+ # gradio_interface.launch()
104
 
105
  # gradio_interface = gradio.Interface(
106
  # fn = responsenew,