Spaces:
Sleeping
Sleeping
# Import necessary libraries | |
import streamlit as st | |
from transformers import AutoModel, AutoTokenizer | |
import PyPDF2 | |
import pytesseract | |
from PIL import Image | |
# Your Hugging Face access token | |
access_token = "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" | |
# Correct model name or path | |
model_name = "bigcode/starcoderplus" | |
# Load StarCoder model and tokenizer | |
model = AutoModel.from_pretrained(model_name, use_auth_token=access_token) | |
tokenizer = AutoTokenizer.from_pretrained(model_name, use_auth_token=access_token) | |
# Streamlit app | |
st.title("Conversational AI Chatbot") | |
# User input for code-related question | |
user_input = st.text_input("Enter your code-related question:") | |
if user_input: | |
# Tokenize and generate code | |
inputs = tokenizer(user_input, return_tensors="pt") | |
outputs = model.generate(**inputs) | |
code = tokenizer.decode(outputs[0]) | |
st.code(code) # Display the generated code | |
# User input for PDF reading | |
pdf_file = st.file_uploader("Upload a PDF file:", type=["pdf"]) | |
if pdf_file: | |
pdf_reader = PyPDF2.PdfFileReader(pdf_file) | |
pdf_text = "" | |
for page_num in range(pdf_reader.numPages): | |
page = pdf_reader.getPage(page_num) | |
pdf_text += page.extractText() | |
st.text(pdf_text) # Display the extracted text | |
# User input for OCR (image to text) | |
image_file = st.file_uploader("Upload an image for OCR:", type=["png", "jpg", "jpeg"]) | |
if image_file: | |
image = Image.open(image_file) | |
ocr_text = pytesseract.image_to_string(image) | |
st.text(ocr_text) # Display the extracted text | |