Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 3 |
+
import torch
|
| 4 |
+
|
| 5 |
+
# Load the fine-tuned model
|
| 6 |
+
model_name = "./tuned_model" # Load from Hugging Face or locally
|
| 7 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
| 8 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 9 |
+
|
| 10 |
+
# Set up Streamlit UI
|
| 11 |
+
st.title("AI Coding Mentor")
|
| 12 |
+
st.write("Ask me any programming-related question!")
|
| 13 |
+
|
| 14 |
+
# User input (question)
|
| 15 |
+
question = st.text_input("Enter your coding question:")
|
| 16 |
+
|
| 17 |
+
if question:
|
| 18 |
+
# Prepare the input for the model
|
| 19 |
+
input_text = f"### Question:\n{question}\n### Answer:"
|
| 20 |
+
inputs = tokenizer(input_text, return_tensors="pt")
|
| 21 |
+
|
| 22 |
+
# Generate the answer using the fine-tuned model
|
| 23 |
+
output = model.generate(**inputs, max_length=200, num_return_sequences=1)
|
| 24 |
+
|
| 25 |
+
# Decode the output
|
| 26 |
+
answer = tokenizer.decode(output[0], skip_special_tokens=True)
|
| 27 |
+
|
| 28 |
+
# Display the result
|
| 29 |
+
st.write(answer)
|