Blane187 commited on
Commit
62f218c
·
verified ·
1 Parent(s): 0430cfb

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -0
app.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import transformers # Replace with your specific library if needed
3
+
4
+ # Load your custom models (example)
5
+ model_name = "microsoft/Phi-3-mini-4k-instruct" # Replace with your model name
6
+ tokenizer = transformers.AutoTokenizer.from_pretrained(model_name)
7
+ model = transformers.AutoModelForCausalLM.from_pretrained(model_name)
8
+
9
+ def chatbot_response(user_input):
10
+ inputs = tokenizer.encode(user_input, return_tensors="pt")
11
+ outputs = model.generate(inputs, max_length=100, num_return_sequences=1)
12
+ response = tokenizer.decode(outputs[0], skip_special_tokens=True)
13
+ return response
14
+
15
+ def upload_readme(file):
16
+ if file is not None:
17
+ content = file.read().decode("utf-8")
18
+ return content
19
+ return "No file uploaded"
20
+
21
+ with gr.Blocks() as demo:
22
+ with gr.Row():
23
+ with gr.Column():
24
+ gr.Markdown("# Chatbot Interface")
25
+ gr.Markdown("Upload your README file and interact with the chatbot.")
26
+
27
+ # File upload
28
+ readme_file = gr.File(label="Upload README file", type="file", file_count="single", file_types=[".md"])
29
+ readme_content = gr.Textbox(label="README Content", lines=10, placeholder="README content will appear here...")
30
+
31
+ # Button to display README content
32
+ readme_file.change(upload_readme, inputs=readme_file, outputs=readme_content)
33
+
34
+ # Chatbot input and output
35
+ user_input = gr.Textbox(label="Your message", placeholder="Type your message here...")
36
+ output = gr.Textbox(label="Chatbot response", placeholder="Chatbot response will appear here...", lines=5)
37
+
38
+ # Button to get chatbot response
39
+ user_input.submit(chatbot_response, inputs=user_input, outputs=output)
40
+
41
+ demo.launch()